Method not found in a Java Bean through xhtml having the exact signature

248 Views Asked by At

I want to make a registration by writing the userEmail, userPassword and userRole in .properties files and then work with them in auth-config.xml. so, i make this in loginManagerBean: i am aware of code duplication in register method, i'll fix it

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 is a named, sessionscope, stateful bean.. the thing is that login is WORKING, but at registration:

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

I have this errors after clicking the register button:

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)
1

There are 1 best solutions below

1
On

Pass the parameter through 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>

In managed bean method get the value like this

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);

      }