我在jsf:
中有一个password recovery
表单
<h:form id="arForm">
<p:panel id="arp">
<p:focus context="arp"/>
<h:panelGrid columns="2" columnClasses="...">
<h:message id="emailMsg" for="email"/>
<h:inputText id="email" value="#{accountBean.email}" required="true" label="email">
<f:validateRegex pattern="..."/>
<f:ajax event="blur" render="emailMsg"/>
</h:inputText>
<p:watermark for="email" value="Enter email address..."/>
<h:commandButton id="recoverBtn" value="Recovery" action="#{accountBean.sendEmail()}" class="recoverBtn">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
</h:panelGrid>
<h:messages id="emailResult" globalOnly="true" showDetail="true"/>
</p:panel>
</h:form>
这是accountBean.sendEmail()
:
public void sendEmail() throws Exception {
boolean sendResult = false;
FacesContext.getCurrentInstance().addMessage("arForm:emailMsg", new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please Wait... "));
sendResult = sendHtmlEmail(...to entered email);
if (sendResult) {
// emailResult message that says there is an internal problem
} else {
// emailResult message that says there is an internal problem
}
}
我希望当用户输入电子邮件并点击Recovery
按钮时,会显示Please Wait...
消息,直到发送电子邮件并显示相应的消息。
但问题是Please Wait...
消息根本没有显示。
答案 0 :(得分:1)
与您的预期相反,视图不会被渲染,直到action方法返回。
您需要在DOM click
事件期间在客户端显示该消息。 JavaScript对此很有帮助。
基本上:
<h:form>
<span id="pleaseWait" style="display:none">Please wait ...</span>
...
<h:commandButton ... onclick="$('#pleaseWait').show()">
<f:ajax ... render="@form" />
</h:commandButton>
</h:form>
(显然内联CSS / JS在实际代码中重构)