【发布时间】:2009-12-11 16:16:58
【问题描述】:
这是微不足道的,但不幸的是我不了解 JSF 中“幕后”的一些过程。所以,我也对相关文章的链接感兴趣。
问题:我有一个用户对象列表。我将这个列表表示为一个数据表。
<h:dataTable var="user" value="#{userService.allUsers}">
<h:column>
<f:facet name="header">
<h:outputText value="Login"/>
</f:facet>
<h:outputText value="#{user.login}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Birthdate"/>
</f:facet>
<h:outputText value="#{user.birthDate}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{user.name}"/>
</h:column>
<h:column>
<!--This form with button is not a real code, just my suggestion how these things should be done-->
<h:form>
<h:commandButton action="openEditForm" value="Edit"/>
</h:form>
</h:column>
</h:dataTable>
现在我想将命令按钮“编辑”添加到每个表格行。单击此按钮应打开一些带有可编辑字段的表单,我们可以在其中更改当前值。
<!--It's not a real code, just my suggestion how these things should be done-->
<h:form>
<h:inputText value="#{user.login}"/>
<h:inputText value="#{user.birthDate}"/>
<h:inputText value="#{user.name}"/>
<h:commandButton action="saveEdits" value="Save"/>
</h:form>
所以,我有两个问题:
- 如何将“编辑”按钮绑定到每一行(即绑定到用户对象)?
- 如何获取编辑形式的用户对象(第二段代码)?
【问题讨论】:
标签: java data-binding jsf