数据表:
<h:form>
<h:panelGroup>
<h:dataTable id="branch-table" value="#{testController.items}" var="item" border="0" >
<h:column>
<f:facet name="header">
<h:outputText value="NAME"/>
</f:facet>
<h:outputText value="#{item.name}"/>
</h:column>
<h:column>
<h:inputText value="#{item.name}"/>
</h:column>
<h:column>
<p:commandButton styleClass="edit" action="#{testController.prepareEdit}" value="" oncomplete="updateForm();"/>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
形式:
<div id="test-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<h:form>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
Details
</div>
<div class="modal-body">
<h:inputText value="#{testController.edit.name}"/>
</div>
<div class="modal-footer">
<p:commandButton action="#{testController.update}" value="#{bundle.CreateBranchSaveLink}"/>
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
<p:remoteCommand name="updateForm" update="@form" oncomplete="$('#test-modal').modal('show');"/>
</h:form>
</div>
准备编辑方法:
public void prepareEdit() {
current = (TestEntity) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
}
编辑方法:
public TestEntity getEdit() {
if (editCurrent == null) {
editCurrent = new TestEntity();
selectedItemIndex = -1;
}
return editCurrent;
}
表格上的通知<h:inputText value="#{testController.edit.name}"/>
。不会显示任何数据,但如果我将其更改为<h:outputText value="#{testController.edit.name}"/>
,将显示正确的数据。
我很困惑为什么会这样。我需要它是 inputText 以便我可以用新值更新它。
*更新
获取项目方法:
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}