Tag: richfaces

  • Rich modalpanel events not populating form values

    So here is a problem I was running into, I usually use rich:modalpanel just to display some data to the user, but the other day I needed to collect some input. After happily submitting my page all the submitted values were null, what the hell. After some research here are my conclusions on this problem.

    We need to put “form” elements inside the modalPanel in order for this to work, and make sure that the ui:insert in our template is not nested within out top form.

    Reason for this is because of where modalpanel is appended to the DOM, that is also a reason why we have a4j:form inside the panel.

    
    
     
    	 
    		
    	
    		
    			
    	   
     
         CONTENT HERE
     
      
       
    
    

    Using Facelets and JSF 1.2

  • Expanding Rich tree nodes programmatically

    I have found two different methods for expanding nodes in Rich tree  from code, they both take  advantage of component binding and component state.

    Tree Setup

    
    	 
    		        
    	 
    
    

    Only thing to note here is the binding attribute that we setup in our backing bean.

    	protected org.richfaces.component.UITree sampleTreeBinding; 
    

    for both solutions after we changed the sampleTree we need to update the binding with new value whitch is
    value="#{ourbean.sampleTree}"

    // Make sure that we set the new TreeModel on current binding
    sampleTreeBinding.setValue(sampleTree);
    

    Solution 1 : Expanding all nodes

    TreeState componentState = (TreeState) sampleTreeBinding.getComponentState();
    try {
    	componentState.expandAll(sampleTreeBinding);
    } catch (IOException e) {
    	e.printStackTrace();
    }
    

    This will expand all levels of the nodes.

    Solution 2 : Expanding only nodes that meet our criteria

    try {
    	final TreeState state = (TreeState) sampleTreeBinding.getComponentState();
    	sampleTreeBinding.walk(FacesContext.getCurrentInstance(), new DataVisitor(){
    		@SuppressWarnings("unchecked")
    		public void process(FacesContext context, Object rowKey, Object argument)
    		throws IOException {
    			TreeRowKey row = (TreeRowKey)rowKey;
    			if(row.depth() == 1){
    				state.expandNode(sampleTreeBinding, (TreeRowKey)rowKey);
    			}
    		}
    	});
    }
    catch (IOException e) {
    	e.printStackTrace();
    }
    
    

    Here we are only expanding nodes at depth 1 but it could be anything. Idea is that we are walking the tree
    and checking if we are interested in the doing something with that node if so then we can modify it here.

    I hope this helps.