How to re-execute <c: select> based on a model change
I'm currently fighting a bit with JSF. I want to display a list of items. Each element can be displayed with two limits (one if the element is editable and the other otherwise).
Code snippet:
<div>
<c:forEach items="#{bean.itemList}" var="item">
<c:choose>
<c:when test="#{bean.isEditable(item.id)}">
<ui:include src="#{item.editableFaceletPath}>
<ui:param name="item" value="#{item}" />
</ui:include>
</c:when>
<c:otherwise>
<ui:include src="#{item.normalFaceletPath}>
<ui:param name="item" value="#{item}" />
</ui:include>
</c:otherwise>
</c:choose>
</c:forEach>
</div>
This works fine until I set the item to be edited. However, if I have 3 elements: item1, item2 and item3, and I set item1 to editable, I get item2, item2, item3.
I understand why this does not work, but I absolutely do not know how I could implement it otherwise. Does anyone know how?
+4
2 answers
, JSTL , JSF , JSTL . JSTL , .
public void someActionMethodWhichSetsItemEditable() {
// Do actual job here.
item.setEditable(true);
// Then rebuild the view (re-executes all JSTL).
FacesContext context = FacesContext.getCurrentInstance();
String viewId = context.getViewRoot().getViewId();
context.setViewRoot(context.getApplication().getViewHandler()
.createView(context, context.getViewRoot().getViewId()));
}
: beans . , beans, , bean postconstruct.
+2