2011-11-24 4 views
3

간단한 JSF 양식을 작성했습니다. 문제는 내가 찾을 수없는 버그가 있다는 것입니다. 기본 페이지를 열고 사용자 이름과 비밀번호를 입력하면 페이지가 다음 페이지로 리디렉션되어야하지만 이것이 일어나지 않습니다. 내 실수를 찾아 내도록 도와 주시겠습니까?양식이 제출되지 않았습니다.

이 메인 로그인 JSF 페이지

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns:h="http://java.sun.com/jsf/html"> 
    <head> 
     <title>Login</title> 
     <link rel="stylesheet" type="text/css" href="resources/css/style.css" /> 
     <script src="resources/js/cufon-yui.js" type="text/javascript"></script> 
     <script src="resources/js/ChunkFive_400.font.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
      Cufon.replace('h1',{ textShadow: '1px 1px #fff'}); 
      Cufon.replace('h2',{ textShadow: '1px 1px #fff'}); 
      Cufon.replace('h3',{ textShadow: '0px 1px #000'}); 
      Cufon.replace('.back'); 
     </script> 
    </head> 
    <body> 
     <div class="wrapper"> 
      <div class="content"> 
       <div id="form_wrapper" class="form_wrapper">      
        <form class="login active"> 
         <h3><center><img src="resources/images/title.png"/></center></h3> 
         <div> 
          <label>Username:</label> 
          <h:inputText value="#{loginController.user}"/> 
          <span class="error">This is an error</span> 
         </div> 
         <div> 
          <label>Password:</label> 
          <h:inputSecret value="#{loginController.password}"/> 
          <span class="error">This is an error</span> 
         </div> 
         <div class="bottom">  
                 <h:commandButton label="Login" value="Login" action="#{loginController.user_compare}"/> 
          <div class="clear"></div> 
         </div> 
        </form>     
       </div> 
      </div>   
     </div> 
    </body> 
</html> 

에게 인이 관리 Bean 당신은 JSF 입력을 얻기 위해 <h:form> 구성 요소를 사용할 필요하고 작업 명령을

/** Bean for checking users and passwords. 
If the user enters the correct username and password 
the user will be redirected to main.xhtml 
If not the page will refresh. */ 

package com.dx.sr_57; 

import java.io.Serializable; 
import javax.enterprise.context.SessionScoped; 
import javax.inject.Named; 


@Named("loginController") 
@SessionScoped 
public class user_check implements Serializable { 
    private String user; 
    private String password; 

     public user_check(){ 
     } 

     public user_check(String user, String password){ 
      super(); 
      this.user = user; 
      this.password = password; 
     } 



     /** get the content of the variables from the JSF Login page */ 

     public String setUser(String newValue) { 
      user = newValue; 
      return user; 
     } 

     public String getUser(){ 
      return user;  
     } 

     public String setPassword(String newValue) { 
      password = newValue; 
      return password; 
     } 

     public String getPassword(){ 
      return password; 
     } 

     public String user_compare() {   
      return "success";   
     } 
} 

답변

4

에게 있습니다.

그래서, 그렇지 않으면 당신은 PropertyNotFoundException에 직면 할 수, 당신은 또한 fullworthy 세터로 당신의 setter를 수정해야

<h:form styleClass="login active"> 
    ... 
</h:form> 

에 의해

<form class="login active"> 
    ... 
</form> 

를 교체합니다.

그래서, 구체적인 문제에

public void setUser(String newValue) { 
     user = newValue; 
    } 

    public void setPassword(String newValue) { 
     password = newValue; 
    } 

관련없는에 의해

public String setUser(String newValue) { 
     user = newValue; 
     return user; 
    } 

    public String setPassword(String newValue) { 
     password = newValue; 
     return password; 
    } 

를 교체하십시오 HTML <center> 태그 는 1998 년부터 사용되지 않는 엄격한 XHTML에서 유효하지 않습니다. 그것을 제거하십시오. 대신 <img>에 CSS text-align: center을 설정해야합니다.

+0

작동합니다! 고맙습니다! –

관련 문제