I am using the dataTable component of PrimeFaces 3.4.2 in JSF 2.1 on Apache Tomcat 6.0.14 --- I want to be able to allow the user to edit rows directly in the table.
Following is my code, somewhat edited for brevity:
page:
Code: Select all
<h:form id="platformSpecForm" style="margin:0px 0px 20px 0px">
<p:dataTable id="platformSpecsTable" editable="true"
value="#{platformView.platformSpecs}" var="pp" rowKey="#{pp.id}" >
<p:ajax event="rowEdit" listener="#{platformView.onPlatformPropertyEdit}"
update=":allMessages,@this" />
<f:facet name="header" >
<h:outputText value="Platform Properties for: #{platformView.platform.title}"/>
</f:facet>
<p:column>
<p:rowEditor/>
</p:column>
<p:column headerText="ID">
<h:outputText value="#{pp.id}"/>
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{pp.specType.title}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="specTypeId" value="#{pp.specTypeId}">
<f:selectItems value="#{platformView.specTypes}" var="st"
itemLabel="#{st.title}" itemValue="#{st.id}" />
</p:selectOneMenu>
<h:message for="specTypeId" class="redError" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{pp.description}"/>
</f:facet>
<f:facet name="input">
<p:inputTextarea id="description" value="#{pp.description}"
maxlength="2000" style="width:95%" rows="4" autoResize="false"/>
<h:message for="description" class="redError"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
Code: Select all
public void onPlatformPropertyEdit(RowEditEvent event) {
try {
PlatformSpec ps = (PlatformSpec) event.getObject(); //grab the object edited
platformSpecService.updatePlatformSpec(ps); //update it in the database
platformSpecs = platformSpecService.getAllByPlatformId(platform.getId()); //re-fetch the entire list
} catch (Exception e) {
HijackError.gotoErrorPage(e);
}
}
If i click the edit icon, make a change, then click the update icon (checkmark), the database is updated as expected. however the table dosn't display the updated value, but instead duplicates a different row.
example - if i have 5 rows, with the IDs 1, 2, 3, 4, and 5... and I edit row 3. after i click the update icon the table will display something like rows 1, 2, 2, 4, and 5... if i refresh the page manually the appropriate data is displayed in the table.
Hopefully someone can easily see what I am doing wrong. Please let me know if you need more code, or other areas that are meaningful to this question. and thank you for your time!