in clValid.jsp, i had used input page
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld" %>
<html>
 <head>
    <title>Strut2's actions</title>
   <s:head/>
 </head>
 <body>
  <center>
   <h1> Service Application</h1>
  <br/>
  <br/>
   <s:form action="ClientValid" validate="true" namespace="/" >
    
        <s:textfield name="applName"  label="Applicant Name:" />
   
        <s:textfield name="charges" label="Payable charges:" />
      
      <s:select label="Service Name:" emptyOption="true"
         list="{'DrivingLicence','ElectricityBill',
         'WaterBill','InsurancePremium'}" 
         name="service" />   
  <s:submit align="center" value="show client-Side validation"/>
 </s:form>
 </center>
</body>
</html> 

 in struts.xml

<package name="htcstruts"
            extends="struts-default">

  <action name="ClientValid"
          class="htcstruts.ClientValidAction">
    
    <result name="success">
          /clResult.jsp
    </result>

    <result name="input">
       /clValid.jsp
    </result>

  </action>
action class is

public class ClientValidAction extends ActionSupport {
 
  private String applName;
  private String service;
  private double charges;
  
  private String resStr;

  private ConcurrentHashMap<String,Double> services;

  public ClientValidAction() {
   services = new ConcurrentHashMap<String,Double>();
   services.put("DrivingLicence",new Double(100.5));
   services.put("ElectricityBill",new Double(40.5));
   services.put("WaterBill",new Double(35.5));
   services.put("InsurancePremium",new Double(30.5));
  }

  public String execute() throws Exception {
   double cost = services.get(service);
   resStr = "hello! "+applName+" Charges for "+
             service+ " are "+cost+".Please ready to pay";
   return SUCCESS;
  }

  public String getResStr() {
   return resStr;
  }

  public String getApplName() {
   return applName;
  }
  
  public void setApplName(String newName) {
   applName = newName;
  }

  public String getService() {
   return service;
  }
  
  public void setService(String newService) {
    service = newService;
  }

  public double getCharges() {
   return charges;
  }
  
  public void setCharges(double newCharge) {
    charges = newCharge;
  }
}

used a validator.xml ClientValidAction-validation.xml

   <!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="applName">

  <field-validator type="requiredstring">

        true

        <message>Applicant's name is required</message>

      </field-validator>

    </field>

    <field name="charges">

     <field-validator type="double">

       9.99

       120.0

<message>
         Charges should be higher than ${minExclusive} and lessequal to
${maxInclusive}
         
       </message>

      </field-validator>

     </field>

  </validators>
 
when i am asking the input , i am getting in browser

FreeMarker template error!

Method public java.util.List
org.apache.struts2.components.Form.getValidators(java.lang.String) threw an
exception when invoked on org.apache.struts2.components.Form@1be20c
The problematic instruction:
----------
==> list tag.getValidators("${tagName}") as validator [on line 46, column 9
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.util.List
org.apache.struts2.components.Form.getValidators(java.lang.String) threw an
exception when invoked on org.apache.struts2.components.Form@1be20c
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.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
at freemarker.core.Environment.visit(Environment.java:417)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.include(Environment.java:1483)
at freemarker.core.Include.accept(Include.java:169)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at
org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:559)
at org.apache.struts2.components.UIBean.end(UIBean.java:513)
at
org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at
org.apache.jsp.clValid_jsp._jspx_meth_s_005fform_005f0(clValid_jsp.java:164)
at org.apache.jsp.clValid_jsp._jspService(clValid_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at
com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.buildValidatorKey(AnnotationActionValidatorManager.java:212)
at
com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:69)
at
com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:65)
at org.apache.struts2.components.Form.getValidators(Form.java:265)
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:597)
at freemarker.ext.beans.BeansWrapper.invokeMet
-- 
View this message in context: 
http://old.nabble.com/client-side-validation-in-struts2-tp30931442p30931442.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to