【发布时间】:2014-06-04 12:15:24
【问题描述】:
我对渲染而不是渲染感到困惑。
首先,我需要输入登录密码和登录按钮。 然后,如果登录密码签出,我需要隐藏所有输入字段和“Enter”按钮,并显示另一个按钮以导航到另一个页面。
最好的方法是什么?
这是我目前所拥有的。
<h:form>
<table>
<h:panelGroup>
<tr><td>Username : </td><td><h:inputText value="#{loginBean.username}"/></td></tr>
<tr><td>Password : </td><td><h:inputSecret value="#{loginBean.password}"/></td></tr>
<tr><td colspan="2">
<h:commandButton value="Enter" action="#{loginBean.login}">
<f:ajax event="change" render="loggedin" listener="#{loginBean.handleEvent}" />
</h:commandButton>
</td></tr>
</h:panelGroup>
<tr><td colspan="2">
<h:commandButton rendered="loginBean.login = false" id="loggedin" value="Go to the special page" action="logingo.xhtml"/>
</td></tr>
</table>
</h:form>
loginBean 的测试非常简单:
@Named(value = "loginBean")
@ManagedBean
@ViewScoped
public class LoginBean {
public boolean result;
private String username = "";
private String password = "";
public boolean output;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Boolean getOutput() {
return output;
}
public void setoutput(String password) {
this.output = output;
}
public void handleEvent(AjaxBehaviorEvent event) {
if (result == true){
output = true;
}
else output = false;
}
public boolean getResult() {
return result;
}
public void setResult(String username) {
this.result = result;
}
public void login() {
if (this.username.isEmpty() == false && this.username.equalsIgnoreCase("11111")
&& this.password.isEmpty() == false && this.password.equals("11111")) {
result = true;
}
result = false;
}
【问题讨论】: