I have an h:dataTable with data generated from an ArrayList with custom object Result.
When I try to enable editing of cells, it will not allow me to do so. I suspect that it request data from the server and overrides my last choice.
My <h:dataTable> form and the complete xhtml document
<!-- language: xhtml -->
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>IGNORED</title>
</h:head>
<h:body>
<ui:composition template="../templates/masterLayout.xhtml">
<ui:define name="windowTitle"> #{msgs.viewResultsTitle}</ui:define>
<ui:define name="content">
<h:form>
<h:dataTable value="#{managedBean.viewResultList}" var="res"
styleClass="tracks"
headerClass="trackHeader"
columnClasses="oddColumn,evenColumn">
<h:column>
<f:facet name="header">#{msgs.trackID}</f:facet>
#{res.track_name}
</h:column>
<h:column>
<f:facet name="header">#{msgs.startnumber}</f:facet>
<h:inputText value="#{res.startnumber}" size="5" rendered="#{res.editable}" />
<h:outputText value="#{res.startnumber}" rendered="#{not res.editable}" />
</h:column>
<h:column>
<f:facet name="header">#{msgs.time}</f:facet>
<h:inputText value="#{res.time}" size="10" rendered="#{res.editable}" >
<f:validator validatorId="ResultValidator" />
<f:converter converterId="ResultConverter" />
</h:inputText>
<h:outputText value="#{res.time}" rendered="#{not res.editable}" />
</h:column>
<h:column>
<f:facet name="header">#{msgs.runnerID}</f:facet>
#{res.runner_name}
</h:column>
<h:column>
<f:facet name="header">#{msgs.divID}</f:facet>
#{res.division_value}
</h:column>
<h:column>
<h:commandLink value="#{msgs.edit}" action="#{managedBean.editAction(res)}" rendered="#{not res.editable}"/>
</h:column>
<h:column>
<h:commandLink value="#{msgs.saveChanges}" action="#{managedBean.saveAction(res)}" />
</h:column>
</h:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
It calls the managedBean.editAction wich looks like this:
public String editAction(Result result) {
result.setEditable(true);
return null;
}
It bassicly set all the result objects to editable. But when I press the it loads the page and nothing happends.
I’ve followed the tut at http://www.mkyoung.com jsf tutorial
Without knowing what your
managedBeanlooks like, here are some hints:viewResultList()should not update the result list but only return it. Otherwise changes to entries in that list might be overwritten if you don’t update your model first (e.g. write them to the database if you load the results from there).result.setEditable(true);seems to refer to one object in your list, or it might even refer to an object not in that list. Note that only that object is set to editable.If you want make all entries editable, you either have to set a global property in your managed bean and check that in your table or iterate over the result list and call
setEditable(true)on each entry in that list.Note that in the example you followed, the
editAction()actually takes an object parameterorderwhich defines which entry inorderListwill be set to editable.