JSF,目标无法访问

时间:2015-06-09 10:13:36

标签: java jsf jsf-2

我遇到与访问对象属性相关的问题。我无法理解发生了什么。我做了很多次,我从来没有这样做过。

我的xhtml页面代码是:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML `enter code here`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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:head>
        <title>Facelet Template</title>
    </h:head>
    <h:body>

       <ui:composition template="./Template.xhtml">

            <ui:define name="top">                
            </ui:define>
            <ui:define name="left"></ui:define>
            <ui:define name="content">
             <h:form>
                    <h:panelGrid columns="2" bgcolor="#EBBBBF">
                        <h:outputText value='#{bMain.getTranslation("username")}'/><h:inputText value="#{bMain.user.username}"/>
                        <h:outputText value='#{bMain.getTranslation("password")}'/><h:inputSecret value="#{bMain.user.password}"/>
                        <h:commandButton value='#{bMain.getTranslation("send")}' action="#{bMain.validateUser()}"/>
                    </h:panelGrid>
             </h:form>
          </ui:define>
       </ui:composition>
    </h:body>
</html>

这是BMain类的代码:

public class BMain {

    private User user; 
    private final Gestor modelo= new Gestor();
    private ArrayList<String> permisos;


    public BMain() {

        Language language = new Language();
        language.setDescription("EN");
        this.user = new User();
        this.permisos= new ArrayList();
        JSFUtil.setAtributte("language", language);

    }    

    public String closeSession(){

        JSFUtil.logOut();
        return "index";
    }

    public String  validateUser(){

        String username = user.getUsername();
        String password = user.getPassword();
        this.user = this.modelo.checkUser(username, password);
        try {
            this.permisos = modelo.getPermisos(user);
        } catch (Exception ex) {
            System.out.println("");
        }

        if(this.user != null){

            JSFUtil.setAtributte("modelo", modelo);
            JSFUtil.setAtributte("user", user);
            JSFUtil.setAtributte("language", user.getLanguage());
            return "inicio";
        } 

            return "index";

    }

    /**
     * @return the usuario
     */
    public User getUser() {
        return user;
    }

    public boolean checkPermisos(String permiso){

        for(int i=0; i<permisos.size(); i++){

            if (permiso.equals(permisos.get(i)))
              return true;

        }

        return false;

    }

     public String getTranslation(String name){

        String translation = "";
        try {
           translation = this.modelo.getTranslation(name);
        } catch (Exception ex) {

        }

        return translation;

    }

}

来自gestor类的方法checkUser:

 public User checkUser(String username, String password) {

        String sql="from User us where us.username='" + username + "' and us.password='" + password +"'";

        ArrayList<User> users;

        try {

            users= (ArrayList<User>) this.seleccionar(sql);
            if(!users.isEmpty() && users.size() == 1){
               User user= users.get(0);
               return user;
            }

        } catch (Exception ex) {
            System.out.println("");
        }


        return null;

    }

0 个答案:

没有答案