Primefaces dataTable rowEditor

时间:2012-12-20 02:01:43

标签: jsf primefaces

我正在使用Primefaces'p:dataTable来显示可编辑的表格。有没有办法检测点击p:rowEditor图标的时间?我需要这个,因为我想在编辑模式下禁用我为行删除添加的p:commandLink

这是.xhtml:

<p:dataTable paginatorAlwaysVisible="true"
                 paginator="true"
                 paginatorPosition="top"
                 paginatorTemplate="{CurrentPageReport} {PageLinks} {RowsPerPageDropdown}"
                 rowsPerPageTemplate="10,25,50"
                 rows="10"
                 editable="true"
                 value="#{userController.allUsers}"
                 var="user"
                 > 
        <p:ajax event="rowEdit" listener="#{userController.onEdit}"/>
        <p:column headerText="First Name">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{user.firstname}"/>
                </f:facet>
                <f:facet name="input">
                    <h:inputText value="#{user.firstname}"/>
                </f:facet>
            </p:cellEditor>
        </p:column>

        //. . . some other data columns

        <p:column headerText="Options">
            <p:rowEditor/> <br/>
            <p:commandLink id="deleteLink" styleClass="ui-icon ui-icon-trash"  action="#{userController.deleteUser(user.userId)}"/>
        </p:column>

在这里我发现相关的bean部分:

@ManagedBean
@SessionScoped
public class UserController {
    @EJB
    private UserBean userBean;
    @EJB
    private TeamBean teamBean;
    private Integer currentUserId;
    private String newUserUsername;
    private String newUserPassword;
    private User.AccountType newUserAccountType;
    private String newUserFirstName;
    private String newUserLastName;
    private Integer newUserTeamId;

    // ... some create/ update/ delete functions that work

    public void onEdit(RowEditEvent event) {
        try {
            User user = (User) event.getObject();
            System.out.println("Edit: " + user);

            userBean.update(user.getUserId(), user.getUsername(), user.getPassword(), 
                User.AccountType.valueOf(user.getAccountType()), user.getFirstname(), user.getLastname(),
                user.getTeam() == null ? null : user.getTeam().getTeamId());
            System.out.println("User " + user.getUserId() + " updated: " + user.getFirstname());
    } catch (InexistentUserException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvalidUsernameException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InexistentTeamException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DataBaseException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}

谢谢!

3 个答案:

答案 0 :(得分:9)

检测单击p:rowEditor的事件是:

<p:ajax event="rowEditInit" listener="#{Bean.someListener}" />

答案 1 :(得分:3)

只需在列中使用其他<p:cellEditor>

<p:column headerText="Options">
  <p:rowEditor/>
  <p:cellEditor>
    <f:facet name="output">
      <p:commandLink id="deleteLink" styleClass="ui-icon ui-icon-trash"  action="#{userController.deleteUser(user.userId)}"/>
    </f:facet>
    <f:facet name="input">

    </f:facet>
  </p:cellEditor>
</p:column>

我还建议您将deleteLink放在另一列中。

答案 2 :(得分:1)

经过大量的研究活动=&#34; rowEditInit&#34;抓住可编辑行的铅笔点击是正确的。

由于