Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:
This 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.
For this example, we are going to create a Sidebar and dynamically add Sidebar groups and links to the Sidebar.Although the example shows how to dynamically create Sidebar groups in a Sidebar component, the same technique should work for any JSF component.
The 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.