在经历了一段绝望的尝试和错误之后,我来找你寻求帮助,因为现在我甚至不确定自己是否做得不对。在ui中没有触发JSF 2.2自定义验证器:重复
我的代码如下所示,显示只读输入文本框中用户配置文件的一些字段。数据来自一个bean,作为“字段”对象的ArrayList,其属性在ui:param指令中描述。 用户可以点击框旁边的解锁/锁定按钮开始/结束编辑她的数据。 当用户在编辑后按下Enter或点击锁定按钮时,我想触发输入验证。
但无论我尝试过,编辑并按下输入或单击按钮后,更改的值不会被写回,并且我的自定义验证程序不会被触发。不知何故,似乎单击按钮后,呈现的输入框不会绑定到该字段?然而,验证工作(和所有属性获得通过它)如果是始终呈现一个输入文本使用的 - 我不明白:)
请看看它。如果我没有足够好地解释我的意图,或者如果您需要更多代码,请告诉我。
编辑:支持bean的注释:
@ManagedBean(name = "beanProfile")
@RequestScoped
了JSF代码:
<ui:composition>
<ui:param name="i18n" value="#{field.i18n}" />
<ui:param name="val" value="#{field.value}" />
<ui:param name="req" value="#{field.required}" />
<ui:param name="min" value="#{field.min}" />
<ui:param name="max" value="#{field.max}" />
<ui:param name="validationType" value="#{field.validationType}" />
<ui:param name="useHidden" value="#{field.hidden}" />
<ui:param name="locked" value="#{field.locked}" />
<ui:param name="fullName" value="#{beanProfile.name}" />
<h:form id="profileFrm">
<h:outputText value="#{msg.role_profile} " styleClass="headingOutputText" />
<h:outputText value="#{fullName}" styleClass="headerTitle" />
<p />
<h:panelGroup>
<ui:repeat var="field" value="#{beanProfile.userFields}">
<h:panelGrid columns="2">
<h:outputText value="#{msg[i18n]}" styleClass="headerTitle" />
<h:message showDetail="true" for="visInput" styleClass="warn"
rendered="#{!useHidden}" />
<h:message showDetail="true" for="invisInput" styleClass="warn"
rendered="#{useHidden}" />
</h:panelGrid>
<h:panelGrid columns="2" columnClasses="nameColumn">
<h:inputText id="visInput" required="true" value="#{val}"
rendered="#{!useHidden}" readonly="#{locked}" >
<f:validator validatorId="customValidator" />
<f:attribute name="requiredField" value="#{req}" />
<f:attribute name="minLen" value="#{min}" />
<f:attribute name="maxLen" value="#{max}" />
<f:attribute name="type" value="#{validationType}" />
</h:inputText>
<h:inputSecret id="invisInput" required="true" value="#{val}"
rendered="#{useHidden}" readonly="#{locked}">
<f:validator validatorId="customValidator" />
<f:attribute name="requiredField" value="#{req}" />
<f:attribute name="minLen" value="#{min}" />
<f:attribute name="maxLen" value="#{max}" />
<f:attribute name="type" value="#{validationType}" />
</h:inputSecret>
<h:commandLink id="lock" action="#{beanProfile.lock(field)}"
rendered="#{!locked}" title="#{msg.profile_lock}">
<h:graphicImage height="16" width="16"
name="images/padlock_unlocked.svg" alt="#{msg.profile_lock}" />
</h:commandLink>
<h:commandLink id="unlock" action="#{beanProfile.unlock(field)}"
rendered="#{locked}" title="#{msg.profile_unlock}">
<h:graphicImage height="16" width="16"
name="images/padlock_locked.svg" alt="#{msg.profile_unlock}" />
</h:commandLink>
</h:panelGrid>
</ui:repeat>
</h:panelGroup>
<p />
<h:commandButton id="submitProfileBtn" value="#{msg.cmd_submit}"
styleClass="button" includeViewParams="true"
action="#{beanProfile.submitProfile()}" />
</h:form>
</ui:composition>
Colud你显示应用于beanProfile' backing bean的注释吗? – lametaweb
更改为ViewScoped范围,包javax.faces.view – lametaweb
我没有和得到这个错误:CDI @ViewScoped管理器不可 – Alfred