简体   繁体   English

f:validateRegex导致异常

[英]f:validateRegex causes exception

I want to validate that an input is strictly numerical consisting of between 10-16 characters long. 我想验证输入是否严格由10到16个字符组成。 Based on the user input value I was going to have a message appear below the input field. 基于用户输入值,我将在输入字段下方显示一条消息。 The problem is, when I go to use <f:validateRegex> to help accomplish this, it causes the app to throw an exception. 问题是,当我去使用<f:validateRegex>来帮助完成此操作时,它将导致应用程序引发异常。

I am new to JSF and I am having a difficult time thinking of ways to debug the application. 我是JSF的新手,我很难思考如何调试应用程序。 The scope of my work is supposed to only really include UI enhancements for now... So I'd like to avoid using a validator class if possible. 我的工作范围目前应该只包含UI增强功能...因此,我希望尽可能避免使用验证器类。

here's the troublesome code. 这是麻烦的代码。 Note: if i remove the tag or comment it out, the page that I'm working will reload without issue. 注意:如果我删除标签或将其注释掉,我正在工作的页面将重新加载而不会出现问题。 Currently, due to the app throwing an exception, the page app will not deliver any code to a requesting browser. 当前,由于该应用引发异常,因此页面应用将无法向请求浏览器传递任何代码。

<h:inputText id="idNum" value="#{object.var}" 
    styleClass="form-control idNum" maxlength="16" 
    required="true" autocomplete="off">
   <f:validateRegex 
      pattern="\^([0-9][\S][^\sa-zA-Z,./;:!:@#$%&*()<>_+~`{}]{8,14})*$\g" />
</h:inputText>
<h:message for="idNum" />

I'd be happy to provide any additional detail. 我很乐意提供其他详细信息。 However, i'm not sure what additional details are relevant at this point. 但是,我不确定目前还有哪些其他细节。 For starters, here's the stack trace: 对于初学者,这是堆栈跟踪:

[8/29/19 21:37:52:386 CDT] 00000093 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException: null source
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1237)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:781)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:480)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
    at org.openfaces.util.FileUploadFilter.doFilter(FileUploadFilter.java:120)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at org.work.app.auth.filter.HeaderFilter.doFilter(HeaderFilter.java:27)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:948)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:287)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
Caused by: java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(EventObject.java:67)
    at javax.faces.event.SystemEvent.<init>(SystemEvent.java:67)
    at javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:69)
    at javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:69)
    at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:256)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:245)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    ... 32 more

[8/29/19 21:37:52:387 CDT] 00000093 webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[Faces Servlet]: java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(EventObject.java:67)
    at javax.faces.event.SystemEvent.<init>(SystemEvent.java:67)
    at javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:69)
    at javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:69)
    at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:256)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:245)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1237)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:781)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:480)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
    at org.openfaces.util.FileUploadFilter.doFilter(FileUploadFilter.java:120)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at org.work.app.auth.filter.HeaderFilter.doFilter(HeaderFilter.java:27)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:948)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:287)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)

I fixed the regex which was causing the error. 我修复了导致错误的正则表达式。 Per the comments, there were at least two culprits causing a problem the & and the < . 根据评论,至少有两个导致&<的问题。 However, just fixing those did not fix the issue. 但是,仅解决这些问题并不能解决问题。 Here's what i did to fix the input. 这是我为修复输入所做的事情。

<h:inputText id="idNum" value="#{object.var}" styleClass="form-control idNum" 
    maxlength="16" required="true" autocomplete="off" requiredMessage="" validatorMessage="No dashes or spaces" binding="#{idNum}">
    <f:validateRegex for="idNum" pattern="(?i-s)(?:[0-9]+){10,16}" />
    <f:ajax immediate="false" event="change" render="idNum-errMsg" />
</h:inputText>
<h:message id="idNum-errMsg" for="idNum" disabled="#{idNum.valid}"  />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM