struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pascal Lalonde <plalo...@auroramsc.com>
Subject Re: NullPointerException with Validation Messages
Date Tue, 09 Sep 2008 12:45:00 GMT
Have you tried this ?

<validators>
    <field name="userName">
        <field-validator type="requiredstring">
            <message key="requiredString"/>
            <!--message key="requiredString">Boo</message-->
        </field-validator>
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message key="requiredString"/>
        </field-validator>
    </field>
</validators>


- Pascal


Mark wrote:
> Hi all:
>
> I'm using Struts 2 validation and I'm getting a NullPointerException 
> when the page is being displayed (before it is even being submitted or 
> validated).  I did some searches and found this Jira: 
> https://issues.apache.org/struts/browse/WW-2150.  It states that it 
> has been fixed in version 2.1.3.  I've updated to the latest SNAPSHOT 
> of 2.1.3 and I'm still getting the error.
>
> The problem seems to be with the <message key...> validation.  If I 
> change it to <message> it works.
>
> Can someone confirm there is not a problem with my setup?
>
> Thanks in advance,
> Mark
>
> My directory structure is as following:
>
> com.myapp.struts
> |
> - LoginAction.java
> - LoginAction-validation.xml
> - package.properties
>
> LoginAction-validation.xml:
> =====================
> <?xml version="1.0" encoding="UTF-8"?>
>     <!DOCTYPE validators PUBLIC
>         "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
>         "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd ">
>
> <validators>
>     <field name="userName">
>         <field-validator type="requiredstring">
>             <message key="requiredString">Boo</message>
>         </field-validator>
>     </field>
>     <field name="password">
>         <field-validator type="requiredstring">
>             <message>Please enter a Password</message>
>         </field-validator>
>     </field>
> </validators>
>
> package.properties
> ================
> <other lines have been snipped>
> requiredString=${getText(fieldName)} is required.
>
> login.jsp
> ================
> <other lines have been snipped>
>            <div id="login">
>                 <h2 align="center">Welcome!    </h2>
>                 <center>
>                 <!--<s:actionerror />-->
>                 <s:if test="hasActionErrors()">
>                     <span class="errorMessage">
>                     <s:iterator value="actionErrors">
>                         <s:property escape="false"/>
>                     </s:iterator>
>                     </span>
>                 </s:if>
>                 <s:form action="login" method="POST" validate="true">
>                     <s:textfield label="Name" name="userName" 
> maxlength="8" size="8px" required="true"/>
>                     <s:password  label="Password" name="password" 
> maxlength="8" size="8px" required="true"/>
>                     <s:submit align="center" value="Login"/>
>                </s:form></center>
>                     <!-- end #mainContent -->
>             </div>
>
> struts.xml
> ==================
> <struts>
>     <include file="struts-default.xml" />
>     <package name="Hotel" extends="struts-default">
>        
>         <interceptors>
>             <interceptor name="mySecurity" 
> class="com.myapp.struts.SecurityInterceptor"></interceptor>
>             <interceptor-stack name="myStack">
>                 <interceptor-ref name="defaultStack"/>
>                 <interceptor-ref name="mySecurity">
>                     <param name="requiredRoles">user</param>
>                 </interceptor-ref>
>             </interceptor-stack>
>         </interceptors>
>         <default-interceptor-ref name="myStack"/>
>
>         <global-results>
>             <result name="noaccess">/noaccess.jsp</result>
>         </global-results>
>
>         <action name="login" class="com.myapp.struts.LoginAction">
>             <result name="input">login.jsp</result>
>             <result>WEB-INF/mainmenu.jsp</result>
>         </action>
> <other lines snipped>
>
> Stack Trace:
> ==================
> 008-09-09 11:05:07,521 ERROR [org.apache.struts2.components.UIBean] - 
> <error when rendering>
> Method public java.lang.String 
> com.opensymphony.xwork2.validator.validators.ValidatorSupport.getMessage(java.lang.Object)

> threw an exception when invoked on 
> com.opensymphony.xwork2.validator.validators.RequiredStringValidator@3b1101 
>
> The problematic instruction:
> ----------
> ==> ${validator.getMessage(action)?js_string} [on line 51, column 26 
> in template/xhtml/form-close-validate.ftl]
>  in include "/${parameters.templateDir}/xhtml/form-close-validate.ftl" 
> [on line 25, column 1 in template/xhtml/form-close.ftl]
> ----------
>
> Java backtrace for programmers:
> ----------
> freemarker.template.TemplateModelException: Method public 
> java.lang.String 
> com.opensymphony.xwork2.validator.validators.ValidatorSupport.getMessage(java.lang.Object)

> threw an exception when invoked on 
> com.opensymphony.xwork2.validator.validators.RequiredStringValidator@3b1101 
>
>     at 
> freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
>     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
>     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>     at freemarker.core.Expression.getStringValue(Expression.java:93)
>     at 
> freemarker.core.StringBuiltins$StringBuiltIn._getAsTemplateModel(StringBuiltins.java:71)

>
>     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>     at freemarker.core.Expression.getStringValue(Expression.java:93)
>     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.MixedContent.accept(MixedContent.java:92)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at 
> freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
>     at freemarker.core.Environment.visit(Environment.java:415)
>     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at 
> freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
>     at freemarker.core.Environment.visit(Environment.java:415)
>     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.MixedContent.accept(MixedContent.java:92)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.MixedContent.accept(MixedContent.java:92)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.Environment.include(Environment.java:1477)
>     at freemarker.core.Include.accept(Include.java:169)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.MixedContent.accept(MixedContent.java:92)
>     at freemarker.core.Environment.visit(Environment.java:208)
>     at freemarker.core.Environment.process(Environment.java:188)
>     at freemarker.template.Template.process(Template.java:237)
>     at 
> org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:185)

>
>     at 
> org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:558)
>     at org.apache.struts2.components.UIBean.end(UIBean.java:512)
>     at 
> org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)

>
>     at 
> org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:344)
>     at org.apache.jsp.login_jsp._jspService(login_jsp.java:139)
>     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>     at 
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) 
>
>     at 
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

>
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

>
>     at 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)

>
>     at 
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)

>
>     at 
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)

>
>     at 
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)

>
>     at 
> org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694) 
>
>     at 
> org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665) 
>
>     at org.apache.jsp.index_jsp._jspService(index_jsp.java:54)
>     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>     at 
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) 
>
>     at 
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

>
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

>
>     at 
> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389) 
>
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

>
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

>
>     at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
>
>     at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
>
>     at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 
>
>     at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
>
>     at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
>
>     at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) 
>
>     at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 
>
>     at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

>
>     at 
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>     at java.lang.Thread.run(Thread.java:613)
> Caused by: java.lang.NullPointerException
>     at 
> com.opensymphony.xwork2.validator.DelegatingValidatorContext$LoggingValidationAware.<init>(DelegatingValidatorContext.java:236)

>
>     at 
> com.opensymphony.xwork2.validator.DelegatingValidatorContext.makeValidationAware(DelegatingValidatorContext.java:195)

>
>     at 
> com.opensymphony.xwork2.validator.DelegatingValidatorContext.<init>(DelegatingValidatorContext.java:46)

>
>     at 
> com.opensymphony.xwork2.validator.validators.ValidatorSupport.getMessage(ValidatorSupport.java:73)

>
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

>
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at 
> freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:835)
>     at 
> freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
>     ... 73 more
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>


-- 

*Pascal Lalonde
Programmeur Analyste*

------------------------------------------------------------------------

/Aurora MSC/
1425 René-Lévesque O Suite 906
Montréal, QC
Bur: 514-664-4745 #227
Fax: 514-664-4767
www.auroramsc.com


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message