我正在使用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>
以下是我认为与Java 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);
}
}
}
谢谢!
p:rowEditor
旁边。 - Cristi