我正在尝试验证以下代码中的输入值,我正在使用正则表达式验证
<h:inputText id="min" maxlength="5" value="#{bean.intValue}"
validatorMessage="Please enter valid Integer value">
<f:validateRegex pattern="^[1-9]\d*$"/>
<f:convertNumber integerOnly="true" />
</h:inputText>
注意 - &GT; intValue
类型为Integer
但是我收到了类别广告的异常,所以下面的消息是说如果是,为什么我们不能使用<f:validateRegex />
Integer
值?
java.lang.Integer无法强制转换为java.lang.String: java.lang.ClassCastException:java.lang.Integer无法强制转换为 java.lang.String at javax.faces.validator.RegexValidator.validate(RegexValidator.java:160) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1]在javax.faces.component.UIInput.validateValue(UIInput.java:1149) javax.faces.component.UIInput.validate中的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIInput.java:967) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1]在javax.faces.component.UIInput.executeValidate(UIInput.java:1233) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1]在javax.faces.component.UIInput.processValidators(UIInput.java:698) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at org.richfaces.context.PartialViewExecuteVisitCallback.visit(PartialViewExecuteVisitCallback.java:55) [richfaces-core-impl-4.3.5.Final.jar:4.3.5.Final] at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:321) [richfaces-core-impl-4.3.5.Final.jar:4.3.5.Final] at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIForm.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIForm.java:371) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at org.richfaces.component.AbstractTab.visitTree(AbstractTab.java:317) [richfaces-components-ui-4.3.5.Final.jar:4.3.5.Final] at org.richfaces.component.AbstractTogglePanel.visitTree(AbstractTogglePanel.java:924) [richfaces-components-ui-4.3.5.Final.jar:4.3.5.Final] at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at org.richfaces.component.AbstractTab.visitTree(AbstractTab.java:317) [richfaces-components-ui-4.3.5.Final.jar:4.3.5.Final] at org.richfaces.component.AbstractTogglePanel.visitTree(AbstractTogglePanel.java:924) [richfaces-components-ui-4.3.5.Final.jar:4.3.5.Final] at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) javax.faces.component.UIForm.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIForm.java:371) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) javax.faces.component.UIComponent.visitTree上的[jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1](UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at org.richfaces.context.ExtendedPartialViewContextImpl.executeComponents(ExtendedPartialViewContextImpl.java:278) [richfaces-core-impl-4.3.5.Final.jar:4.3.5.Final] at org.richfaces.context.ExtendedPartialViewContextImpl.processPartialExecutePhase(ExtendedPartialViewContextImpl.java:258) [richfaces-core-impl-4.3.5.Final.jar:4.3.5.Final] at org.richfaces.context.ExtendedPartialViewContextImpl.processPartial(ExtendedPartialViewContextImpl.java:215) [richfaces-core-impl-4.3.5.Final.jar:4.3.5.Final] at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1162) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.19-redhat-1.jar:2.1.19-redhat-1] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.19-redhat-1.jar:2.1.19-redhat-1] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.19-redhat-1.jar:2.1.19-redhat-1] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar:2.1.19.1.Final-redhat-1] at at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at com.alu.ipprd.bsm.soa.portal.edgefilter.EdgeFilter.doFilter(EdgeFilter.java:29) [班级:] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10] at at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] at java.lang.Thread.run(未知来源)[rt.jar:1.7.0_79]
修改 -
由于 @BalusC 已经回复了here,但我希望无法输入任何小数值,也不应输入01
或{{1}之类的值}