- This topic has 1 reply, 1 voice, and was last updated 19 years, 2 months ago by Robin zou.
-
AuthorPosts
-
Robin zouMemberHi,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]
Robin zouMemberI 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!
-
AuthorPosts