I have a list of different objects, which should get rendered each in it's own way based by it's type (eg. String = HtmlInputText, Text = HtmlInputText, ...). Based on one of the Answers in StackOverflow I decided to do this via binding. Currently I have the following construct:
...
<h:head>
<h:outputScript library="javax.faces" name="jsf.js" target="head" />
</h:head>
<h:body>
<h:form id="form">
<h:panelGrid binding="#{componentBean.grid}">
</h:panelGrid>
</h:form>
</h:body>
</html>
My ComponentBean is a request scoped bean (because of the binding) which just holds the binded Grid and sets the list of components. private HtmlPanelGrid grid:
@Inject
private EntityBean entityBean;
@PostConstruct
public void init() {
grid = new HtmlPanelGrid();
initComponents();
}
public void initComponents() {
for (Slot slot : entityBean.getEntity().getSlots()) {
if (slot.getType().getTypeClass().equals(TypeClass.ForeignKey))
grid.getChildren().add(entityBean.getComponent(slot.getID()));
}
}
...
And my thought was that I have a second bean called EntityBean which holds the created UIComponents in a list, so they don't get reinitialized each request. This works pretty well so far. My Problem now is, that regarding on the actions (eg. a SelectOneMenu has changed in a certain way) I have to redraw the html components in my request scoped ComponentBean. I used Ajax in the selectOneMenu to do my action (eg. removing one component from the list). Now the problem is that my ComponentBean init() is getting called BEFORE my actionListener is called, so the components get redrawn before the action happens. I want the action to happen and redraw the component afterwards. Does anyone have a clue about what I could possibly do here?