2017-02-13 32 views
0

我想通過在.properties文件中編寫userEmail,userPassword和userRole來進行註冊,然後在auth-config.xml中使用它們。所以,我認爲這種方式loginManagerBean: 我所知註冊方法的代碼重複,我會解決它通過具有確切簽名的xhtml在Java Bean中找不到的方法

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是一個命名,sessionscope,狀態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) 

回答

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

     } 
+0

感謝狀值..完成,但仍然沒有工作:「javax.servlet.ServletException:javax.el.MethodNotFoundException:/模板/註冊。 xhtml @ 33,92 action =「#{loginManager.register}」:找不到方法:class「..該bean被命名爲(loginManager),並在登錄時看到來自loginManager的方法,但是在註冊時它給我提供了錯誤。真的不知道發生了什麼事 – Nica

相關問題