JSF 2.1 雄猫 7.0
这是对依赖注入的错误使用吗?
它可以在页面上移动。但是“它有效”与“它是正确的”不同。
我也会将此模式用于搜索目的。我有一个请求,我喜欢用它来填充同一页面中的表格。这可能吗?
索引.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html">
<h:head>
<link rel="SHORTCUT ICON" href= "resources/img/onlyT.ico"></link>
<title>title</title>
<h:outputStylesheet library="css" name="compass.css"/>
</h:head>
<h:body>
Login system
<br />
<h:form>
User : <h:inputText value="#{user.username}" />
Password : <h:inputSecret value="#{user.password}" />
<h:commandButton action="#{loginBean.performLogin()}" value="Submit" />
<h:commandButton value="reset" type="reset" />
<h:commandButton value="ChangePsW" action="changePassword"></h:commandButton>
</h:form>
<h:message for="" style="color:red;margin:8px;"/>
</h:body>
</html>
LoginBan.java
@ManagedBean
@RequestScoped
public class LoginBean {
@ManagedProperty(value="#{user}")
private UserBean userBean;
//must povide the setter method
public void setUserBean(UserBean userBean) {
this.userBean = userBean;
}
public LoginBean() {}
public String performLogin(){
//Mi connetto al db
if(userBean.getUsername().equalsIgnoreCase( "mario")){
//effettuo i controlli per stabilire se esiste l'utente
userBean.setRoles("-EE-E-E-E-E-E");
return "/mainPortal/mainPortal";
}
return "/mainPortal/index";
}
}
用户Bean.java
@ManagedBean (name="user")
@SessionScoped
public class UserBean implements Serializable {
private String Username;
private String Password;
private String Roles;
/** Creates a new instance of UserBean */
public UserBean() {
}
/**
* @return the Username
*/
public String getUsername() {
return Username;
}
/**
* @param Username the Username to set
*/
public void setUsername( String Username ) {
this.Username = Username;
}
/**
* @return the Password
*/
public String getPassword() {
return Password;
}
/**
* @return the Roles
*/
public String getRoles() {
return Roles;
}
/**
* @param Roles the Roles to set
*/
public void setRoles( String Roles ) {
this.Roles = Roles;
}
/**
* @param Password the Password to set
*/
public void setPassword( String Password ) {
this.Password = Password;
}
更改密码也使用userBean,并拥有他的changePasswordBean。