我在jsf项目中检索实体列表并与托管bean类进行整体交互时遇到了一些问题。 这是班级
@Named(value = "userRegistrationController")
@ViewScoped
public class UserRegistrationController implements java.io.Serializable{
@EJB
UserFacade ejbFacade;
private User current;
private List<User> userList;
public UserRegistrationController() {
}
public String populateUsers(){
this.userList = ejbFacade.findAll();
System.out.println("SIZE == "+userList.size());
return "admin/currentUsers";
}
public String print(){
return "EJBFACADE = "+ejbFacade.findAll().size()+" | = "+userList.size();
}
public String flowHandler(FlowEvent event){
if(current != null){
System.out.println("current: "+current);
if(!current.isEnableNotifications()){
return "confirm";
}else{
return event.getNewStep();
}
}
else{
return event.getNewStep();
}
}
public String create(){
int userCount = ejbFacade.findAll().size();
current.setId(BigDecimal.valueOf(userCount+1));
ejbFacade.create(current);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Successful User Entry", "Successful User Entry"));
return null;
}
// getters setters
当我从带有
的xhtml页面调用它时<p:dataTable id="registeredUserList" value="#{userRegistrationController.userList}" var="u">..</>
部分jsf页面与p:cellEditor :
<f:view>
<body>
<f:event type="preRenderView" listener="#{userRegistrationController.populateUsers}"/>
<ui:composition template="../layout/template.xhtml">
<ui:define name="content">
<h1>Current Registered Users</h1><br/>
<h:form id="currentUserForm">
<h:outputText value="#{userRegistrationController.print}"/>
<p:dataTable id="registeredUserList" value="#{userRegistrationController.userList}" var="u"
editable="true" editMode="cell">
<p:ajax event="cellEdit" listener="#{userRegistrationController.cellEditAction}"
update=":currentUserForm:currentUsersFormMessages"/>
<p:column id="firstName" headerText="First">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.first}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="firstNameInput" value="#{u.first}"/>
</f:facet>
</p:cellEditor>
</p:column>
..........
这是在添加修复
之前正常工作的方法userRegistrationController.cellEditAction
public void cellEditAction(CellEditEvent event) {
System.out.println("INSIDE CELLEDIT");
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (newValue != null && !newValue.equals(oldValue)) {
FacesMessage message = new FacesMessage("The " + event.getColumn().getHeaderText() + " column has been changed to " + newValue);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
事实上,它在faces消息中显示正确的更改值,但无法将其保存到User对象。