dynamicaly adding components to panel/grid
I am trying to add components dynamically in panelgrid but it is displaying nothing.in jsp tag is
<h:panelGrid id = "ExpenseDetail" binding = "#{expenses.component}" />
tand his is what i am doing in backing bean.
public HtmlPanelGrid getComponent()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
component = new HtmlPanelGrid();
component.getChildren().clear();
component.setBorder(1);
component.setColumns(1);
component.setStyleClass("browsetabletype2");
component.setWidth("90%");
UIOutput outText = (UIOutput)application.createComponent("javax.faces.HtmlOutputText");
outText.setValue("Name");
outText.setId("Name");
component.getChildren().add(outText);
return component;
}
[888 byte] By [
shila] at [2007-10-2 18:25:02]

What about setter of your binded component ?
Try this
private HtmlPanelGrid dynamicPanel = null;
public HtmlPanelGrid getDynamicPanel {
if (this.dynamicPanel == null) {
// this will happen the first time the HtmlPanelGrid is retrieved
this.dynamicPanel = new HtmlPanelGrid();
}
try {
generatePanel(this.dynamicPanel);
} catch (Exception e) {
e.printStackTrace();
}
return dynamicPanel;
}
public void setDynamicPanel(HtmlPanelGrid dynamicPanel) {
try {
generatePanel(dynamicPanel);
} catch (Exception e) {
e.printStackTrace();
}
this.dynamicPanel = dynamicPanel;
}
private void generatePanel(HtmlPanelGrid dynamicPanel){
dynamicPanel.getChildren().clear();
dynamicPanel.setId("dynamicPanel_1");
//adding other attributes and children ...
}
I always use this method, and it works. Maybe there is more sophisticated way, but I didn't managed to find it. Hope it helps.
Martin
How do you know how many rows, and what type of components should your panelGride have ?
I'm generating my forms acording to values from DB.
So I have ArrayList of objects with values from DB. Then i iterate over this list and create whole panelGrid with components. If i want to delete row, i remove from list some objectes. If I want to add row, I add specified number of objects into list.
But I think it's not what you expecting.
Martin
If U want to add header to generated panelGrid try this
HtmlPanelGrid panelGrid = new HtmlPanelGrid();
Map facets = panelGrid.getFacets();
HtmlOuputText outputText = new HtmlOutputText();
outputText.setValue("MY header text");
facets.put("header",outputText );
If Your list of elements on panelGrid does'nt change dynamicly, why are U using component binding and dynamicly generated components ?
Martin
never done this before, but try to iterate over panelGrid's childrens
panelGrid.getChildren();
check if each of children is HtmlSelectBooleanCheckbox
with instanceof
If its checkbox and value of its true then remove
all components from i to column count (where i is your courrent iteration position)
panelgrid.getChildren().remove(i);
But I realy don't know if it's gonna work :)
Good luck ;)
Martin