使用javax.ejb.EJB发出在jsf托管bean中检索数据的问题;

时间:2017-09-28 16:15:59

标签: jsf java-ee cdi

我在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对象。

0 个答案:

没有答案