0

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)
Nica
  • 55
  • 9

1 Answers1

1

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

      }
Divagar Haldurai
  • 399
  • 2
  • 3
  • 11
  • thanks .. done, but still not working:"javax.servlet.ServletException: javax.el.MethodNotFoundException: /templates/register.xhtml @33,92 action="#{loginManager.register}": Method not found: class ".. the bean is named(loginManager) and at the login it sees the methods from loginManager, but at registration it gives me errors.. really don t know what's happening – Nica Feb 14 '17 at 16:51