Enrique Medina wrote:
Just some comments...
Set preserveDataModel to true does not work with checkboxes placed
inside the table (as the typical way to select some rows to, for
example, delete all selected).
It seems that there is an order problem when MyFaces serializes them
to preserve the dataModel, so the checkboxes get mixed between
requests...
Has anyone faced this problem?
I worked around that problem with an event-caching system:
I posted the solution partially in the thread before...
What you can do is to implement an h:commandLink within a row, pass down
a positional parameter and to the checking of the dataset within some
kind of cache on the backend side of things, that way you cannot loose
any positional data until you clear the cache.
On the frontend side of things, you just have to simulate a checkbox by
checking if the current dataset is checked within the backend cache or
not...
Here is the code again with additional data so that you get an idea:
<h:commandLink action="#{DiffsyschangelogMaster.selectForOperation}">
<h:outputText id="selected" value="[x]"
rendered="#{bean.selectedForOperation}" />
<h:outputText id="notselected" value="[ ]"
rendered="#{!bean.selectedForOperation}" />
<f:param name="beanId" value="#{bean.id}" />
</h:commandLink>
and on the backend following happens:
public String selectForOperation() {
if(selForOpTriggered) return Constants.NAV_CMD_FORWARD;
selForOpTriggered = true;
FacesContext context = FacesContext.getCurrentInstance();
Map params =
context.getExternalContext().getRequestParameterMap();
String beanId = (String) params.get("beanId");
if(StringUtils.isEmpty(beanId)) return "notprepared";
BaseDatabaseObject obj = dataModel.getPageObjectFromId(new
Integer(beanId));
obj.setSelectedForOperation(!obj.isSelectedForOperation());
selForOpTriggered = true;
return Constants.NAV_CMD_REFRESH;
}
the caching of the bean is done within the model itself, the bean is not
dumped from the cache until the next paging... hence the
#{bean.selectedForOperation}" works on the frontend, but there are
thousands of ways you can achieve the same without caching on the model
stage, for instance you could store the id in the session and then check
for being selected against the session, or you could serialize the
checkstate.