我正在使用 Primefaces 开发一个移动 Web 应用程序,并希望集成客户端验证,但它不起作用。移动渲染套件似乎与它不兼容,或者我可能忘了做点什么。谁能帮助我?先感谢您。
问题是当我使用:
<context-param>
<param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
<param-value>true</param-value>
</context-param>
和
<default-render-kit-id>PRIMEFACES_MOBILE</default-render-kit-id>
和
validateClient="true" attribute,
即使启用了ajax,也不会调用客户端验证脚本,并且在我单击commandButton 后页面会自动刷新。
在 Web 浏览器中,一旦加载页面,我就会出现此 java 脚本错误:
validators.js;jsessionid=1409a4a5b3f93be1b8d3134bfcce:1 未捕获类型错误:无法在 validators.js 处设置未定义的属性“custom.emailValidator”;jsessionid=1409a4a5b3f93be1b8d3134bfcce:1
当我删除 PRIMEFACES_MOBILE 时,一切正常,没有任何错误
这是我的 sign_in.xhtml :(对于 javascript 和 EmailValidator,我从 Primefaces Showcase 复制了示例代码)
我还在一个页面中包含了多个 pm:pages。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:pm="http://primefaces.org/mobile"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<pm:page id="sign_in">
<pm:content>
<h1 id="kie_title" align="center">KIE</h1>
<h:form id="form_sign_in">
<p:messages id="messages" autoUpdate="true" globalOnly="true"/>
<pm:field>
<p:panelGrid columns="1">
<p:outputLabel for="email" value="Email"/>
<p:inputText id="email" value="#{signInCtrl.email}" required="true">
<!--<f:validateRegex pattern="[a-zA-Z]*"/>-->
<f:validator validatorId="custom.emailValidator"/>
</p:inputText>
<p:message for="email"/>
</p:panelGrid>
</pm:field>
<pm:field>
<p:panelGrid columns="1">
<p:outputLabel for="password" value="Password"/>
<p:password id="password" value="#{signInCtrl.password}" required="true"/>
</p:panelGrid>
<p:message for="password"/>
</pm:field>
<p:commandButton id="cmdbtn_sign_in" value="Sign In" action="#{signInCtrl.signIn()}" validateClient="true"
update="@form"/>
</h:form>
</pm:content>
<!--Block fixed to the bottom of the page with New user and Forgot password links-->
<div id="new_user">
<p:button outcome="pm:sign_up?transition=slide" value="Sign Up"/>
<p:link outcome="pm:password_recovery?transition=slide" value="Forgot your password ?"/>
</div>
</pm:page>
</ui:composition>