Nov
27

Creating Dynamic Components at JSF is really easy but because of performance problems and the large number of components to generate i choose different way at project. A simple sample:

Use datagrid/datatable object to add your components:

<h:panelgrid id="grid1″ styleclass="panelGrid" columns="2></h:panelgrid> <hx:commandexbutton id="newComponentBtn"

action="#{pc_DynaComponentView.addNewComponent}" styleclass="commandExButton"

type="submit" value="New Component">

</hx:commandexbutton>

Sample JSF:

<h:form id="form1" styleclass="form"> <h:panelgrid id="grid1" styleclass="panelGrid" columns="2"></h:panelgrid>

<hx:commandexbutton id="newComponentBtn"

action="#{pc_DynaComponentView.addNewComponent}" styleclass="commandExButton"

type="submit" value="New Component"></hx:commandexbutton>

<h:panelgrid id="grid1" styleclass="panelGrid" columns="2"></h:panelgrid>

<hx:commandexbutton id="newComponentBtn"

action="#{pc_PageView.addNewComponent}" styleclass="commandExButton"

type="submit" value="New Component"></hx:commandexbutton>

</h:form>

Sample Code at Backing Bean:

public void addNewComponent() {
// create sample components
HtmlSelectOneListbox listbox = new HtmlSelectOneListbox();
HtmlInputText text1 = new HtmlInputText();
text1.setValue("TEST");
List valueList = new ArrayList();
SelectItem selectItem = new SelectItem("TEST1", "TEST1");
valueList.add(selectItem);
selectItem = new SelectItem("TEST2", "TEST2");
valueList.add(selectItem);
UISelectItems items = new UISelectItems();
items.setValue(valueList);
listbox.getChildren().add(items);
grid1 = getGrid1();
// Add components
grid1.getChildren().add(listbox);
grid1.getChildren().add(text1);
}
Category: jsf  Tags:
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
One Response
  1. Helen Lee says:

    How do you bind back bean component with user action. For example, how do you get the value when user types in something in input textfield?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>