JSF h:inputText验证和f:ajax渲染 [英] JSF h:inputText validation and f:ajax render
问题描述
一个非常简单的JSF应用程序:
A very simple JSF applicaton:
- InputText元素与Validator一起分配。
- f:ajax用于通过
blur
事件呈现下一个元素(phoneNumber)。 - 仅当inputText传递验证器并且isValid布尔值设置为true时才会显示PhoneNumber
- InputText element is assigned with Validator.
- f:ajax is used to render next element (phoneNumber) by using
blur
event. - PhoneNumber will only be displayed if inputText pass the validator and isValid boolean value is set to true
这是代码片段
<h:form id="invOrdersWizForm">
<h:inputText id="name" maxlength="9" styleClass="ordLabelNarrow"
validator="#{person.validatePerson}"
value="#{person.name}">
<f:ajax render="phoneLabel" event="blur"/>
</h:inputText>
<h:outputText id="phoneLabel"
rendered="#{person.isValid}"
styleClass="ordLabelWide" value="#{person.phoneNumber}" />
</h:form>
ManagedBean
ManagedBean
public void validatePerson(FacesContext context, UIComponent toValidate, Object value) {
name = ((String) value).toUpperCase();
phoneNumber = "12345678";
isValid = true;
}
问题是,由于某种原因,phoneNumber根本没有呈现。
The problem is, for some reason, the phoneNumber is not rendered at all.
我能让它发挥作用的唯一方法是改变f:ajax来渲染@form
The only way that I can make it work is by changing f:ajax to render @form
<h:inputText id="name" maxlength="9" styleClass="ordLabelNarrow"
validator="#{person.validateSecurityCode}"
value="#{person.name}">
<f:ajax render="@form" event="blur"/>
</h:inputText>
或从phoneNumber中删除呈现
Or remove rendered from phoneNumber
rendered="#{person.isValid}"
由于某种原因f:具有特定元素Id的ajax和基于managedBean Attribute的呈现不能共存。
For some reason f:ajax with specific element Id and rendered based on managedBean Attribute cannot co-exist.
任何想法或建议的人?
注意:当我使用监听器而不是验证器时也会发生这种情况
NOTE: this behaviour also happen when I use listener instead of validator
推荐答案
f:ajax
在客户端运行。 render
中指定的元素必须已存在于客户端HTML DOM树中。把它放在例如 h:panelGroup
中,而不是总是呈现给客户端。
The f:ajax
operates at the client side. The element which is specified in render
must be already present in the client side HTML DOM tree. Put it in for example a h:panelGroup
instead which is always rendered to the client side.
<h:panelGroup id="phoneLabel">
<h:outputText rendered="#{person.isValid}" value="#{person.phoneNumber}" />
</h:panelGroup>
这篇关于JSF h:inputText验证和f:ajax渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!