facebook

How to render core components in custom component renderer?

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #239047 Reply

    Robin zou
    Member

    Hi,i got a piece of jsf code like this:

    <h:panelGrid columns="1">
       
                    //show1 part
                      <h:dataTable value="#{temp.nameFile}" var = "myL" rendered="#{temp.show1}">
                      <h:column>
                        <h:commandLink action="#{temp.createBean}" value="#{myL.name}" immediate="true">
                       <f:param name="name" value="#{myL.name}"/>
                       <f:param name="path" value="#{myL.path}"/>
                     </h:commandLink>  
                     </h:column>
                     </h:dataTable>
                 
              </h:panelGrid>

    now i want to write my own custom component and use a very simple tag to get the same output,and the tag may look like this:

    <robin:category scheme="iso3166"> </robin:category>  

    But i don’t want to write the html code directly in my renderer to render the components like dataTable and command link.so the code to render the above components is like this:

    public void encodePart1(FacesContext context, UIComponent component,
                ResponseWriter writer)
        {
    
            /* create the components */
    
            // create the out most panel grid
            HtmlPanelGrid topPanelGrid = new HtmlPanelGrid();
            topPanelGrid.setColumns(1);
    
            // ********create the data table in part1*********
            HtmlDataTable dataTable = new HtmlDataTable();
            // set value attribute
            ValueBinding valueBinding = MyUtil.createValueBinding(context,
                    "#{temp.nameFile}");
            dataTable.setValueBinding("value", valueBinding);
            // set var attribute
            dataTable.setVar("myL");
            // set rendered attribute
            ValueBinding renderBinding = MyUtil.createValueBinding(context,
                    "#{temp.show1}");
            dataTable.setValueBinding("rendered", renderBinding);
    
            dataTable.setParent(topPanelGrid);
            // **************create the column*************
            UIColumn column = new UIColumn();
    
            column.setParent(dataTable);
            // **************create the command link*************
            HtmlCommandLink commandLink = new HtmlCommandLink();
            ValueBinding actionBinding = MyUtil.createValueBinding(context,
                    "#{temp.createBean}");
            commandLink.setValueBinding("action", actionBinding);
    
            ValueBinding linkValueBinding = MyUtil.createValueBinding(context,
                    "#{myL.name}");
            commandLink.setValueBinding("value", linkValueBinding);
    
            commandLink.setImmediate(true);
    
            commandLink.setParent(column);
            // ***********create the params***********
            UIParameter param1 = new UIParameter();
            ValueBinding p1Binding = MyUtil.createValueBinding(context,
                    "#{myL.name}");
            param1.setName("name");
            param1.setValueBinding("value", p1Binding);
    
            UIParameter param2 = new UIParameter();
            ValueBinding p2Binding = MyUtil.createValueBinding(context,
                    "#{myL.path}");
            param1.setName("path");
            param1.setValueBinding("value", p2Binding);
    
            param1.setParent(commandLink);
            param2.setParent(commandLink);
    
            // renders the components
            try
            {
                topPanelGrid.encodeBegin(context);
                dataTable.encodeBegin(context);
                dataTable.encodeChildren(context);
                dataTable.encodeEnd(context);
                topPanelGrid.encodeChildren(context);
                topPanelGrid.encodeEnd(context);
            } catch (java.io.IOException ioe)
            {
                FacesMessage message = new FacesMessage("IOException");
                context.addMessage(null, message);
            }
        }

    As you see, i create the instances of the components,set the attribute value bindings,and set the parent-child relationships.Finally,i invoke the encode begin method of parent components.But the result page is a blank page, the components are not rendered.Can i render the components this way?or I must write the according html code for each component?
    Best Regards:)
    Robin[/b]

    #239048 Reply

    Robin zou
    Member

    I changed the code in the try-catch block to the following code(i use myfaces):

    
     HtmlGridRenderer gridRenderer=new HtmlGridRenderer();
                 gridRenderer.encodeBegin(context,topPanelGrid);
                 gridRenderer.encodeChildren(context,topPanelGrid);
                 gridRenderer.encodeEnd(context,topPanelGrid);
    

    it also doesnt work.please help!

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: How to render core components in custom component renderer?

You must be logged in to post in the forum log in