在每个查询中,记录都是变量,只需要编辑最后一条记录,即单元格Total-Student。
<p:panel style="width:40%; margin: 0 auto; margin-top: 20px;">
<h:form>
<p:dataTable id="aviableCuotas" var="pag" value="#{loginController.pagos}">
<p:column headerText="Year" styleClass="tableHeader">
<h:outputText value="#{pag.year}" styleClass="tableContent"/>
</p:column>
<p:column headerText="Total Students" styleClass="tableHeader">
<h:outputText value="#{pag.estadistic}" styleClass="tableContent" />
</p:column>
</p:dataTable>
</h:form>
<h:form>
<p:commandButton value="Calculate" action="#{loginBean.getLogin}" style="float: right" />
</h:form>
</p:panel>
如果您只想编辑一列,请使用:
<p:dataTable id="aviableCuotas" var="pag" value="#{loginController.pagos}" editable="true" editMode="cell">
<p:column headerText="Year" styleClass="tableHeader">
<h:outputText value="#{pag.year}" styleClass="tableContent"/>
</p:column>
<p:column headerText="Total Students" styleClass="tableHeader">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{pag.estadistic}" styleClass="tableContent" /> </f:facet>
<f:facet name="input"><p:inputText value="#{pag.estadistic}" styleClass="tableContent"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
如果你想修改最后一行,使用
<p:dataTable id="aviableCuotas" var="pag" value="#{loginController.pagos}" editable="true" editMode="cell" rowIndexVar="i">
<p:column headerText="Year" styleClass="tableHeader">
<h:outputText value="#{pag.year}" styleClass="tableContent"/>
</p:column>
<p:column headerText="Total Students" styleClass="tableHeader">
<p:cellEditor rendered="#{i == (loginController.pagos.size() - 1)}">
<f:facet name="output"><h:outputText value="#{pag.estadistic}" styleClass="tableContent" /> </f:facet>
<f:facet name="input"><p:inputText value="#{pag.estadistic}" styleClass="tableContent"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>