gpt4 book ai didi

jsf - 如何在不验证所有必需输入的情况下调用命令按钮?

转载 作者:行者123 更新时间:2023-12-03 03:29:53 26 4
gpt4 key购买 nike

我正在尝试从index.xhtml 重定向到registerFirstTime.xhtml。

页面index.xhtml中的代码是:

<h:form id="content" style="margin-top: 1em;">
<p:panel id="panel" header="LOGIN">
<p:messages id="msgs" globalOnly="true"/>
<h:panelGrid columns="3">
<h:outputLabel value="e-mail" />
<p:inputText id="name" required="true" value="#{UserBean.email}"
requiredMessage="Required: e-mail" display="icon">
</p:inputText>
<p:message id="msgName" for="name"/>
<h:outputLabel value="Password" />
<p:password id="password" required="true" value="#{UserBean.password}"
requiredMessage="Required: Password" display="icon" feedback="false">
</p:password>
<p:message id="msgPassword" for="password"/>
</h:panelGrid>
<h:panelGrid columns="2">
<p:commandButton value="Login" actionListener="#{UserBean.validate}" update="msgNombre, msgPassword, msgs"/>
<h:commandButton value="Register for the first time" action="register"/>
</h:panelGrid>
</p:panel>
</h:form>

而faces-config.xml中的重定向内容是:

<navigation-rule>
<from-view-id>index.xhtml</from-view-id>
<navigation-case>
<from-outcome>register</from-outcome>
<to-view-id>registerFirstTime.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

在输入名称和密码填写完毕之前,您无法进行重定向。如何在不考虑必填字段的情况下重定向记录?谢谢! =)

最佳答案

添加immediate="true"到命令按钮,该按钮应跳过对所有不具有 immediate="true" 的输入字段的处理属性。

<h:commandButton value="Register for the first time" action="register" immediate="true" />
<小时/>

与具体问题无关,请注意,从技术上讲,您并没有在此处发送重定向。这基本上会发送一个转发,即浏览器地址栏中的 URL 仍然是登录页面的 URL。您需要添加<redirect/><navigation-case> 。另请注意,导航案例是 JSF 1.x 的遗留物。从 JSF 2.x 开始,您可以执行“隐式导航”,只需指定 View ID 作为结果。

<h:commandButton value="Register for the first time" action="registerFirstTime?faces-redirect=true" immediate="true" />

这样您就可以完全摆脱导航案例。

关于jsf - 如何在不验证所有必需输入的情况下调用命令按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11243652/

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