【问题标题】:Method not found in a Java Bean through xhtml having the exact signature通过具有确切签名的 xhtml 在 Java Bean 中找不到方法
【发布时间】:2017-07-01 10:21:06
【问题描述】:

我想通过在 .properties 文件中写入 userEmail、userPassword 和 userRole 来进行注册,然后在 auth-config.xml 中使用它们。所以,我在 loginManagerBean 中做这个: 我知道注册方法中的代码重复,我会修复它

public void register(String Remail, String Rpassword, String Rrole) throws InvalidUserException{
    Properties prop = new Properties();
    InputStream in = getClass().getResourceAsStream("auction-roles.properties");
    try {
        prop.load(in);
        prop.setProperty(Remail,Rrole);
        prop.store(new FileOutputStream("auction-roles.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Properties prop2 = new Properties();
    InputStream in2 = getClass().getResourceAsStream("auction-users.properties");
    try {
        prop2.load(in2);
        prop2.setProperty(Remail,Rpassword);
        prop2.store(new FileOutputStream("auction-users.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    login(Remail,Rpassword);

}

LoginManager 是一个命名的、会话范围的、有状态的 bean.. 问题是登录是有效的,但在注册时:

<h:commandButton id="registerButton" value="register"
        action="#{loginManager.register(registerEmail, registerPassword, registerRole)}"/>

点击注册按钮后出现这个错误:

javax.servlet.ServletException: javax.el.MethodNotFoundException: /templates/register.xhtml @34,86 action="#{loginManager.register(registerEmail, registerPassword, registerRole)}": Method not found: class org.auction.LoginManager$244422980$Proxy$_$$_Weld$EnterpriseProxy$.register(java.lang.String, java.lang.String, java.lang.String)

【问题讨论】:

    标签: session jsf xhtml javabeans facesservlet


    【解决方案1】:

    通过 f:param 传递参数

        <h:commandButton id="registerButton" value="register" action="#{loginManager.register} />
            <f:param name="regEmail" value="registerEmail" />
            <f:param name="regPwd" value="registerPassword" />
            <f:param name="regRole" value="registerRole" />
         </h:commandButton>
    

    在托管 bean 方法中获取这样的值

    public void register(){ 
    
    Map<String, String> resMap = (Map<String, String>) externalContext.getRequestParameterMap();
    String Remail= parameterMap.get("regEmail");
    String Rpassword= parameterMap.get("regPwd");
    String Rrole= parameterMap.get("regRole");
    
             Properties prop = new Properties();
    InputStream in = getClass().getResourceAsStream("auction-roles.properties");
    try {
        prop.load(in);
        prop.setProperty(Remail,Rrole);
        prop.store(new FileOutputStream("auction-roles.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    Properties prop2 = new Properties();
    InputStream in2 = getClass().getResourceAsStream("auction-users.properties");
    try {
        prop2.load(in2);
        prop2.setProperty(Remail,Rpassword);
        prop2.store(new FileOutputStream("auction-users.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    login(Remail,Rpassword);
    
          }
    

    【讨论】:

    • 感谢 .. 完成,但仍然无法正常工作:"javax.servlet.ServletException: javax.el.MethodNotFoundException: /templates/register.xhtml @33,92 action="#{loginManager.register} ": Method not found: class ".. bean 被命名(loginManager) 并且在登录时它看到来自 loginManager 的方法,但是在注册时它给了我错误.. 真的不知道发生了什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    相关资源
    最近更新 更多