SummaryThis article will show you how to build components at run time as the component is rendered, using NetAdvantage for JSF dynamically. The components will be created in the Java server-side code of the backing bean, instead of using tags to create the components in the JSP page. This is useful if either the contents or the format of the component is not known until run time. |
Additional Information |
Step-By-Step ExampleThe first step is to create the tags in the JSP page that will create a place holder for the Sidebar and bind it to the backing bean as shown in the code below: In JSP:
What this does to create a Sidebar component and bind it to the backing bean. When the page gets rendered the binding="#{webbar_dynamic.sidebar}" tag will cause the setSidebar(Sidebar bar) method in the backing bean to be called. In the backing bean, the setSidebar(Sidebar bar) needs to dynamically construct the Sidebar groups and add them to the Sidebar using the FacesContext. This process is similar to creating an XML document though code with a DOM Object: you create a set of objects and then arrange them in a hierarchical order, in the same manner as the tags would be arranged on the JSP page. To create a Sidebar group you would first construct one in the FacesContext and set its properties as follows: In Java:
The next step is to create some items to add to the Sidebar group. In this example, we are going add a hyperlink. In Java:
The final line in the last set of code aSidebarGroup.getChildren().add(aLink1); adds to the link as a child member of the Sidebar group. The last step is to add the Sidebar group with its link to the Sidebar. In Java:
Setting up the sample: After downloading the sample using the link below, put the contents in the \documentation\tutorials folder underneath the installation directory for NetAdvantage for JSF. The sample works the same as all the other tutorials, and has a build.xml file that will allow you to build and run the sample. |
SamplesDemonstrates how to dynamically add groups to a JSF Sidebar component |
The information in this article applies to:
JSF WebBar (v6.1.20061)
Screenshot:
0 comments:
Post a Comment