기본적으로 input.xhtml에는 사용자 이름과 암호를 사용하는 양식이 있으며 특정 값과 같으면 값은 중요하지 않음) 프로그램은 브라우저에서 메시지를 인쇄해야하지만 이는 발생하지 않습니다. 문제를 확인하기 위해 "System.out.println (...)"의 두 줄을 추가하여 속성의 값을 출력하고 내가 찾은 바는 속성을 제출 한 후에도 여전히 null이라는 것입니다. 그래서 콘솔에서 보내기를 클릭하면 "null null"이라고 기록됩니다. 어떤 도움을 주셔서 감사합니다!Java ee와 jsf 2,2를 사용하여 양식을 제출 한 후, 내 backing bean 특성이 여전히 null입니다.
이것은이 UserBean 클래스 (백업 콩)입니다
package bean;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class UserBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
private String password;
private String output_message;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String go(){
output_message = "";
if(name == null && password == null){
output_message += "Both fields cannot be empty!";
}else if(name == "name" && password == "pass"){
output_message += "Success!";
}else{
output_message += "Data is wrong!";
}
System.out.println(name);
System.out.println(password);
return output_message;
}
public String getOutput_message() {
return output_message;
}
public void setOutput_message(String output_message) {
this.output_message = output_message;
}
public String ret(String r){
return r;
}
}
이는 빈에 데이터를 제출 양식을 포함하는 input.xhtml 파일입니다. 버튼 HTML 태그에 의한
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:cc="http://java.sun.com/jsf/composite/myComponent">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="content">
<style type="text/css">
#form1{
position: absolute;
top: 20%;
left:40%;
border: 1px solid black;
background-color: orange;
}
td{
padding-top:10px;
}
input[type="text"]{
backgorund-color:blue;
}
</style>
<form id="form1" method="post">
<table columns="2">
<tr>
<td><span>Emri:</span></td>
<td><input type="text" id="emri" value="#{userBean.name}"/></td>
</tr>
<tr>
<td><span>Password:</span></td>
<td><input type="password" id="pass" value="#{userBean.password}"/></td>
</tr>
<tr>
<td colspan="2" align="center"><button type="submit" onclick="#{userBean.go()}">Send</button></td>
</tr>
</table>
</form>
<p>#{user.output_message}</p>
</ui:define>
</ui:composition>
</html>
아래에서 내 대답을 확인하십시오. 도와 주셔서 대단히 감사합니다! @ Bitman – AldiT
오 예. 나는 그것을 잡지 못했다. JSF로 처리, 유효성 검사 등을 원한다면 h : 네임 스페이스의 입출력 컴포넌트를 사용해야한다. –