gpt4 book ai didi

java - 如何使用 f :ajax? 使 jsf 更改按下按钮后呈现的内容

转载 作者:行者123 更新时间:2023-11-30 11:18:01 25 4
gpt4 key购买 nike

我对渲染和不渲染感到困惑。

首先,我需要输入登录密码和登录按钮。然后,如果登录密码被验证,我需要隐藏所有输入字段和“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;
}

最佳答案

您在 rendered 属性方面走在了正确的轨道上。但是你的语法有点不对。

它应该是这样的:

rendered="#{loginBean.login}"

使用它时,如果登录返回 true 并且如果您希望条件检查为 false,则将呈现,试试这个:

rendered="#{!loginBean.login}"

希望对您有所帮助! :)

关于java - 如何使用 f :ajax? 使 jsf 更改按下按钮后呈现的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24037203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com