如何将表行绑定到jsf中的Edit-button?

Rom*_*man 2 java data-binding jsf

这是微不足道的,但不幸的是我不了解JSF中的"幕后"流程.所以,我也对相关文章的链接感兴趣.

问题:我有一个用户对象列表.我将此列表表示为dataTable.

<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>
Run Code Online (Sandbox Code Playgroud)

现在我想将commandButton"Edit"添加到每个表行.单击此按钮应该打开一些带有可编辑字段的表单,我们可以在其中更改当前值.

<!--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>
Run Code Online (Sandbox Code Playgroud)

所以,我有两个问题:

  1. 如何将"编辑"按钮绑定到每一行(即用户对象)?
  2. 如何以编辑形式获取用户对象(第二块代码)?

Boz*_*zho 6

<h:commandLink id="editlink" value="#{msg.edit}" action="myEditPageNavRule">
    <f:setPropertyActionListener value="#{user}"
        target="#{userBean.user}" />
 </a4j:commandLink>
Run Code Online (Sandbox Code Playgroud)

#{user}你的dataTable var 在哪里 根据userBean的范围,打开编辑页面时将获得相应的数据.(它肯定会与会话范围一起使用,如果你的navigationRule没有'重定向',我认为你的请求范围也是如此).

上面的代码只是将当前User对象设置为target属性.