Java Code Examples for javax.faces.component.UIViewRoot#processUpdates()

The following examples show how to use javax.faces.component.UIViewRoot#processUpdates() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DojoCheckBoxDefaultValueDisabledTest.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * @param root
 * @param contextForPost
 * @return
 * @throws IOException
 */
private String doSubmitAndRedisplay(UIViewRoot root, FacesContext contextForPost) throws IOException {
    String page;
    // now fake the JSF lifecycle
    root.processDecodes(contextForPost);
    root.processValidators(contextForPost);
    if( contextForPost.getMessages().hasNext() ){
        fail("messages found after validate");
    }
    root.processUpdates(contextForPost);
    root.processApplication(contextForPost);
    if( contextForPost.getMessages().hasNext() ) fail("messages found");
    ResponseBuffer.initContext(contextForPost);
    page = ResponseBuffer.encode(root, contextForPost);
    return page;
}
 
Example 2
Source File: ChangeDynamicContentTest.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public void testChangeDynamicContent() throws Exception {
	
       // first create the view using a regular get command
       Application app = TestProject.createApplication(this);
       FacesContext context = TestProject.createFacesContext(this); // [0]first get request
       String fullViewName = "/pages/testChangeDynamicContentAction.xsp";
       UIViewRoot root = TestProject.loadView(this, context, fullViewName);
       
       // verify the test has not been misconfigured
       AssertUtil.assertInstanceOf(DesignerApplicationEx.class, app);
       
       String fails = "";
       fails += checkComputedFieldPresence(root, 0);
       
       // the next request created is as explained in the method below
       for (int i = 1; i < expectedArr.length; i++) {
           int requestNum = i;
           
           Map<String, String> extraParams = new HashMap<String, String>();
           extraParams.put("view:_id1", "");
           extraParams.put("$$xspsubmitid", (String)expectedArr[requestNum][0]);
           HttpServletRequest request = TestProject.createRequest(this, fullViewName, extraParams);
           FacesContext contextForPost = TestProject.createFacesContext(this,request);
           ResponseBuffer.initContext(contextForPost);
           contextForPost.setViewRoot(root);
           
           // now fake the JSF lifecycle
           root.processDecodes(contextForPost);
           root.processValidators(contextForPost);
           if( contextForPost.getMessages().hasNext() ){
               fail("messages found after validate");
           }
           root.processUpdates(contextForPost);
           root.processApplication(contextForPost);
           
           if( contextForPost.getMessages().hasNext() ) fail("messages found");
           
           fails += checkComputedFieldPresence(root, requestNum);
           
           Boolean expectActionFoo = (Boolean) expectedArr[requestNum][4];
           if( null != expectActionFoo ){
               UIComponent actionDiv = findComponent(root, "actionDiv");
               if( null == actionDiv ){
                   fails += "[" +requestNum+"] unexpected absence of actionDiv in control tree.\n";
                   continue;
               }
               String pageSnippet = ResponseBuffer.encode(actionDiv, contextForPost);
               String actionValue = expectActionFoo?"foo":"";
               AssertUtil.assertContains(
                       pageSnippet,
                       "<span id=\"view:_id1:dynamicContent1:computedField4\">"
                               + actionValue + "</span>");
           }
       }
       if( fails.length() > 0 ){
           fail(XspTestUtil.getMultilineFailMessage(fails));
       }
}