Controller Bean没有拿起用户名

时间:2013-04-25 08:45:56

标签: jpa eclipselink glassfish-3 ejb-3.1 jsf-2.2

我真的遇到了严重的问题。突然间,我正常工作的代码停止了工作。我不知道为什么这么做!!!!最糟糕的是,我今天必须部署我的项目:(。不知道是否说得对,但所有这一切都是在构建路径中添加PrimeFaces后2天开始的。有人可以指引我到正确的方向会很有帮助!

我有以下配置:

  1. Glassfish v3
  2. Mojara 2.1.6-FCS
  3. JPA Eclipselink
  4. 控制器Bean

    public List<Usergroupdetail> getUsergroupdetail_list() {
            List<Usergroupdetail> myUserGroupDetail = new ArrayList<Usergroupdetail>(
                    lODBN.listUserGroupDetail(loginBean.getUsername()));
            System.out.println("username found is:" + loginBean.getUsername());
            return myUserGroupDetail;
        }
    

    从JPA PoJO UserGroupReport获取完整的数据列表

    public List<Usergroupreport> getGroupId_list() {
        List<Usergroupreport> myAllgroupIds = new ArrayList<Usergroupreport>(
                lODBN.findAllGroupIdByUser(loginBean.getUsername()));
        return myAllgroupIds;
    }
    

    堆栈跟踪

    WARNING: PWC4011: Unable to set request character encoding to ISO-8859-1 from context /WebApp, because request parameters have already been read, or ServletRequest.getReader() has already been called
    FINE: SELECT ROWID, GROUPID, GROUPNAME, USERNAME FROM usergroupdetail WHERE (USERNAME = ?)
        bind => [1 parameter bound]
    INFO: []
    INFO: username found is:null
    FINE: SELECT ROWID, GROUPID, GROUPNAME, USERNAME FROM usergroupdetail WHERE (USERNAME = ?)
        bind => [1 parameter bound]
    
    INFO: []
    INFO: username found is:null
    FINE: SELECT ROWID, GROUPID, GROUPNAME, USERNAME FROM usergroupdetail WHERE (USERNAME = ?)
        bind => [1 parameter bound]
    INFO: []
    INFO: username found is:null
    FINE: SELECT RowId, LOD1COSTCENTER, LOD1DISPLAYNAME, LOD1DOMAIN, LOD1MAIL, LOD1USER, LOD2COSTCENTER, LOD2DISPLAYNAME, LOD2DOMAIN, LOD2MAIL, LOD2USER, Access, AuthentifizierteBenutzer, Auto, Comment, Comment1, Comment2, Comment3, Domain1, Domain2, EmailFeedback, EmailSendStatus, RechteGruppeChange, RechteGruppeRead, Security, Type, Username FROM lodreport WHERE (Username = ?)
        bind => [1 parameter bound]
    INFO: []
    INFO: LOD list for Username :null
    FINE: SELECT RowId, LOD1COSTCENTER, LOD1DISPLAYNAME, LOD1DOMAIN, LOD1MAIL, LOD1USER, LOD2COSTCENTER, LOD2DISPLAYNAME, LOD2DOMAIN, LOD2MAIL, LOD2USER, Access, AuthentifizierteBenutzer, Auto, Comment, Comment1, Comment2, Comment3, Domain1, Domain2, EmailFeedback, EmailSendStatus, RechteGruppeChange, RechteGruppeRead, Security, Type, Username FROM lodreport WHERE (Username = ?)
        bind => [1 parameter bound]
    INFO: []
    INFO: LOD list for Username :null
    FINE: SELECT RowId, LOD1COSTCENTER, LOD1DISPLAYNAME, LOD1DOMAIN, LOD1MAIL, LOD1USER, LOD2COSTCENTER, LOD2DISPLAYNAME, LOD2DOMAIN, LOD2MAIL, LOD2USER, Access, AuthentifizierteBenutzer, Auto, Comment, Comment1, Comment2, Comment3, Domain1, Domain2, EmailFeedback, EmailSendStatus, RechteGruppeChange, RechteGruppeRead, Security, Type, Username FROM lodreport WHERE (Username = ?)
        bind => [1 parameter bound]
    INFO: []
    INFO: LOD list for Username :null
    

    登录Bean

    package bean;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    //import javax.annotation.PostConstruct;
    import javax.ejb.EJB;
    import javax.faces.application.FacesMessage;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;
    
    import ejb.UserDaoBean;
    import ejb.UserGroupDaoBean;
    
    import model.User;
    
    @ManagedBean(name = "loginBean")
    @SessionScoped
    public class LoginBean implements Serializable {
    
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
    
        @EJB
        private UserDaoBean uDB;
        @EJB
        private UserGroupDaoBean uGDB;
        private User userId;
    
        public List<User> usernameFirstLastName;
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
        public String firstName;
    
        public String lastName;
    
        public String password;
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public List<User> getUsernameFirstLastName() {
            List<User> myName = new ArrayList<User>(uDB.findFirtLastNames(username));
            return myName;
        }
    
        public void setUsernameFirstLastName(List<User> usernameFirstLastName) {
            this.usernameFirstLastName = usernameFirstLastName;
        }
    
        private String username;
    
    
        public User getUserId() {
            return userId;
        }
    
        public void setUserId(User userId) {
            this.userId = userId;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String login() {
            FacesContext context = FacesContext.getCurrentInstance();
    
            if (uDB.validateUser(username,password)) {
                userId = uDB.findUser(username);
    
                context.getExternalContext().getSessionMap().put("userId", userId);
                if (uGDB.validateGroup(userId)) {
                    return "home.jsf?faces-redirect=true&amp;includeViewParams=true";
                }
                return "normalHome.jsf?faces-redirect=true&amp;includeViewParams=true";
    
            } else {
                FacesMessage message = new FacesMessage();
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                message.setSummary("Username doesn't exists! OR User is trying to login from someone else's account");
                context.addMessage("", message);
                return "newloginerror.jsf?faces-redirect=true";
            }
        }
    
        public String logout() {
            FacesContext.getCurrentInstance().getExternalContext()
                    .invalidateSession();
            return "logout.jsf?faces-redirect=true";
        }
    
    
    }
    

    登录页面

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <link href="./css/PageLayout.css" rel="stylesheet" type="text/css" />
        <title>Login</title>
    </h:head>
    <h:body>
        <f:view>
            <div style="background-color: #205a8c; width: auto; height: 60px">
                <h3 style="font-size: large; position: relative;" align="left">Lord
                    Of Data Web App</h3>
            </div>
            <div id="wrappers">
                <div class="content pls centering">
                    <h:form>
                        <table class="form_table" style="background-color: silver;">
                            <tbody>
                                <tr>
                                    <td>Username</td>
                                    <td><h:inputText id="inputusername"
                                            value="#{loginBean.username}" required="true"
                                            requiredMessage="Username is required!"></h:inputText> <h:message
                                            for="inputusername"></h:message></td>
                                </tr>
    
                                <tr>
                                    <td>Password</td>
                                    <td><h:inputSecret id="inputpassword"
                                            value="#{loginBean.password}" required="true"
                                            requiredMessage="Password is required!"></h:inputSecret> <h:message
                                            for="inputpassword"></h:message></td>
                                </tr>
                            </tbody>
                        </table>
                        <div id="buttonsoptions" align="center" style="padding-top: 10px;">
                            <h:panelGroup>
                                <tr>
                                    <td><h:commandButton id="login" value="Login"
                                            action="#{loginBean.login}"></h:commandButton></td>
                                </tr>
    
                            </h:panelGroup>
                        </div>
                    </h:form>
                </div>
            </div>
        </f:view>
    </h:body>
    </html>
    

    用于登录身份验证的EJB代码段

    public boolean validateUser(String username, String password) {
            try {
                Query myQuery = entityManager.createNamedQuery("userverification")
                        .setParameter("username", username)
                        .setParameter("password", password);
                User result = (User) myQuery.getSingleResult();
    
                if (result != null) {
                    System.out.println("Loggin sucessful!");
                    return true;
    
                } else {
                    System.out.println("User does not exists in the system");
                    return false;
                }
            } catch (NoResultException e) {
    
                return false;
            }
    
        }
    

    我尝试将用户名用于我的其他会话bean,直到两天后它才能正常工作。这是我尝试调用从登录bean中选择的用户名的bean的代码

    package bean;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.annotation.PostConstruct;
    import javax.ejb.EJB;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    
    import ejb.LODReportDaoBean;
    import ejb.LordOfDataDaoBeanNormal;
    import ejb.UserDaoBean;
    
    import model.Lodreport;
    import model.Usergroupdetail;
    import model.Usergroupreport;
    
    @ManagedBean(name = "lordOfDataNormalUserBean")
    @SessionScoped
    public class LordOfDataNormalUserBean implements Serializable {
    
        /**
         * @author Sushant Pandey
         */
        private static final long serialVersionUID = 1L;
    
        @EJB
        private LordOfDataDaoBeanNormal lODBN;
    
        @EJB
        private UserDaoBean uDB;
    
        @EJB
        private LODReportDaoBean lONRDB;
    
        @ManagedProperty(value = "#{loginBean}")
        private LoginBean loginBean;
    
        public LoginBean getLoginBean() {
            return loginBean;
        }
    
        public void setLoginBean(LoginBean loginBean) {
            this.loginBean = loginBean;
        }
    
        public List<Lodreport> lodnormal_list;
    
        public List<Usergroupreport> usergroup_list;
    
        public List<Usergroupdetail> usergroupdetail_list;
    
        public List<Lodreport> findDataByRowId;
    
        private Lodreport myreport = new Lodreport();
    
        public Lodreport getMyreport() {
            return myreport;
        }
    
        public void setMyreport(Lodreport myreport) {
            this.myreport = myreport;
        }
    
        public void setFindDataByRowId(List<Lodreport> findDataByRowId) {
            this.findDataByRowId = findDataByRowId;
        }
    
        public int security;
        public String username;
        public String access;
        public String authentifizierteBenutzer;
        public String auto;
        public String comment;
        public String comment1;
        public String comment2;
        public String comment3;
        public String domain1;
        public String domain2;
        public String emailFeedback;
        public String emailSendStatus;
        public String lOD1CostCenter;
        public String lOD1DisplayName;
        public String lOD1Domain;
        public String lOD1Mail;
        public String lOD1User;
        public String lOD2CostCenter;
        public String lOD2DisplayName;
        public String lOD2Domain;
        public String lOD2Mail;
        public String lOD2User;
        public String rechteGruppeChange;
        public String rechteGruppeRead;
        public String type;
        public int rowId;
    
        public List<Usergroupreport> groupId_list;
    
        public boolean edit;
    
        public boolean isEdit() {
            return edit;
        }
    
        public void setEdit(boolean edit) {
            this.edit = edit;
        }
    
        public void setGroupId_list(List<Usergroupreport> groupId_list) {
            this.groupId_list = groupId_list;
        }
    
        public void setLodnormal_list(List<Lodreport> lodnormal_list) {
            this.lodnormal_list = lodnormal_list;
        }
    
        public int getSecurity() {
            return security;
        }
    
        public void setSecurity(int security) {
            this.security = security;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String getAccess() {
            return access;
        }
    
        public void setAccess(String access) {
            this.access = access;
        }
    
        public String getAuthentifizierteBenutzer() {
            return authentifizierteBenutzer;
        }
    
        public void setAuthentifizierteBenutzer(String authentifizierteBenutzer) {
            this.authentifizierteBenutzer = authentifizierteBenutzer;
        }
    
        public String getAuto() {
            return auto;
        }
    
        public void setAuto(String auto) {
            this.auto = auto;
        }
    
        public String getComment() {
            return comment;
        }
    
        public void setComment(String comment) {
            this.comment = comment;
        }
    
        public String getComment1() {
            return comment1;
        }
    
        public void setComment1(String comment1) {
            this.comment1 = comment1;
        }
    
        public String getComment2() {
            return comment2;
        }
    
        public void setComment2(String comment2) {
            this.comment2 = comment2;
        }
    
        public String getComment3() {
            return comment3;
        }
    
        public void setComment3(String comment3) {
            this.comment3 = comment3;
        }
    
        public String getDomain1() {
            return domain1;
        }
    
        public void setDomain1(String domain1) {
            this.domain1 = domain1;
        }
    
        public String getDomain2() {
            return domain2;
        }
    
        public void setDomain2(String domain2) {
            this.domain2 = domain2;
        }
    
        public String getEmailFeedback() {
            return emailFeedback;
        }
    
        public void setEmailFeedback(String emailFeedback) {
            this.emailFeedback = emailFeedback;
        }
    
        public String getEmailSendStatus() {
            return emailSendStatus;
        }
    
        public void setEmailSendStatus(String emailSendStatus) {
            this.emailSendStatus = emailSendStatus;
        }
    
        public String getlOD1CostCenter() {
            return lOD1CostCenter;
        }
    
        public void setlOD1CostCenter(String lOD1CostCenter) {
            this.lOD1CostCenter = lOD1CostCenter;
        }
    
        public String getlOD1DisplayName() {
            return lOD1DisplayName;
        }
    
        public void setlOD1DisplayName(String lOD1DisplayName) {
            this.lOD1DisplayName = lOD1DisplayName;
        }
    
        public String getlOD1Domain() {
            return lOD1Domain;
        }
    
        public void setlOD1Domain(String lOD1Domain) {
            this.lOD1Domain = lOD1Domain;
        }
    
        public String getlOD1Mail() {
            return lOD1Mail;
        }
    
        public void setlOD1Mail(String lOD1Mail) {
            this.lOD1Mail = lOD1Mail;
        }
    
        public String getlOD1User() {
            return lOD1User;
        }
    
        public void setlOD1User(String lOD1User) {
            this.lOD1User = lOD1User;
        }
    
        public String getlOD2CostCenter() {
            return lOD2CostCenter;
        }
    
        public void setlOD2CostCenter(String lOD2CostCenter) {
            this.lOD2CostCenter = lOD2CostCenter;
        }
    
        public String getlOD2DisplayName() {
            return lOD2DisplayName;
        }
    
        public void setlOD2DisplayName(String lOD2DisplayName) {
            this.lOD2DisplayName = lOD2DisplayName;
        }
    
        public String getlOD2Domain() {
            return lOD2Domain;
        }
    
        public void setlOD2Domain(String lOD2Domain) {
            this.lOD2Domain = lOD2Domain;
        }
    
        public String getlOD2Mail() {
            return lOD2Mail;
        }
    
        public void setlOD2Mail(String lOD2Mail) {
            this.lOD2Mail = lOD2Mail;
        }
    
        public String getlOD2User() {
            return lOD2User;
        }
    
        public void setlOD2User(String lOD2User) {
            this.lOD2User = lOD2User;
        }
    
        public String getRechteGruppeChange() {
            return rechteGruppeChange;
        }
    
        public void setRechteGruppeChange(String rechteGruppeChange) {
            this.rechteGruppeChange = rechteGruppeChange;
        }
    
        public String getRechteGruppeRead() {
            return rechteGruppeRead;
        }
    
        public void setRechteGruppeRead(String rechteGruppeRead) {
            this.rechteGruppeRead = rechteGruppeRead;
        }
    
        public String getType() {
            return type;
        }
    
        public void setType(String type) {
            this.type = type;
        }
    
        public int getRowId() {
            return rowId;
        }
    
        public void setRowId(int rowId) {
            this.rowId = rowId;
        }
    
        public void setUsergroup_list(List<Usergroupreport> usergroup_list) {
            this.usergroup_list = usergroup_list;
        }
    
        public void setUsergroupdetail_list(
                List<Usergroupdetail> usergroupdetail_list) {
            this.usergroupdetail_list = usergroupdetail_list;
        }
    
        @PostConstruct
        public void init() {
            // getLodnormal_list();
            getUsergroupdetail_list();
    //      getGroupId_list();
            getUsername();
        }
    
        public String displayReport() {
    
            getLodnormal_list();
    
            return "reportLordOfDataNormal.jsf?faces-redirect=true";
        }
    
        public List<Lodreport> getLodnormal_list() {
            List<Lodreport> myLodreport = new ArrayList<Lodreport>(
                    lODBN.reportLODNormal(loginBean.getUsername()));
            System.out.println("LOD list for Username :" + loginBean.getUsername() );
            return myLodreport;
        }
    
    
        public List<Usergroupreport> getUsergroup_list() {
            return usergroup_list;
        }
    
        public List<Usergroupdetail> getUsergroupdetail_list() {
            List<Usergroupdetail> myUserGroupDetail = new ArrayList<Usergroupdetail>(
                    lODBN.listUserGroupDetail(loginBean.getUsername()));
            System.out.println("username found is:" + loginBean.getUsername());
            return myUserGroupDetail;
        }
    
        public String editLODDataNormal() {
    
            lODBN.updateExistingLODDataNormal(security, loginBean.getUsername(),
                    access, authentifizierteBenutzer, auto, comment, comment1,
                    comment2, comment3, domain1, domain2, emailFeedback,
                    emailSendStatus, lOD1CostCenter, lOD1DisplayName, lOD1Domain,
                    lOD1Mail, lOD1User, lOD2CostCenter, lOD2DisplayName,
                    lOD2Domain, lOD2Mail, lOD2User, rechteGruppeChange,
                    rechteGruppeRead, type, rowId);
    
            return "reportLordOfDataNormal.jsf?faces-redirect=true";
    
        }
    
        public List<Usergroupreport> getGroupId_list() {
            List<Usergroupreport> myAllgroupIds = new ArrayList<Usergroupreport>(
                    lODBN.findAllGroupIdByUser(loginBean.getUsername()));
            return myAllgroupIds;
        }
    
        public void edit(Lodreport myreport) {
            this.myreport = myreport;
            edit = true;
        }
    
        public void saveMyReport(){
            lONRDB.updateReport(myreport);
        }
    
    }
    

0 个答案:

没有答案