gpt4 book ai didi

JSF FacesContext#addMessage 不显示

转载 作者:行者123 更新时间:2023-12-05 00:00:19 24 4
gpt4 key购买 nike

在我的 previous question我遇到了从登录表单显示验证消息的问题。该问题现已解决,但这次我无法显示带有 FacesContex#addMessage 的自定义消息.

使用 JSF + PrimeFaces。

<p:dialog header="Login" widgetVar="loginDlg">
<h:form id="loginForm">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}" id="username" required="true" label="username" />
<p:message for="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}" id="password" required="true" label="password" />
<p:message for="password" />
<f:facet name="footer">
<p:commandButton value="Login" id="loginDlgButton" update=":loginForm,:welcomeMsg" actionListener="#{loginBean.login}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
<p:message for="loginDlgButton" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>

登录 bean (一个 SessionScoped ManagedBean):
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
RequestContext rContext = RequestContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
try {
request.login(this.username, this.password);
rContext.addCallbackParam("loggedIn", true);
} catch (ServletException e) {
rContext.addCallbackParam("loggedIn", false);
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials"));
}
}

当验证成功且登录失败时,此代码应显示“凭据无效”消息,但不会显示。此外,在我的网页正文的某处,我还添加了这一行:
<p:messages autoUpdate="true" />

但我的消息甚至没有显示在那里。

Javadocs比如说

If clientId is null, this FacesMessage is assumed to not be associated with any specific component instance



但我无法理解这是什么意思。

最佳答案

地点 <p:messages autoUpdate="true" />在您的 form 内或在一些由 update 更新的包装器中您的 commandButton ,或放置 loginDlgButton而不是 nullcontext.addMessage(...

关于JSF FacesContext#addMessage 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396572/

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