tags:

views:

597

answers:

3

Hi all,

I am trying a very simple struts2 (2.1.6) application using velocity (1.6.2 and tools 2.0 beta4) ,

It's nothing more than a simple form with a single textfield.

The code follows

 ## Velocity Template.   
<html>   
    <head>   
        <title>Struts2 and velocity </title>   
   </head>   

    <body>   

     pass this message:   

     $sform("action=Amma"  "validate=true")   

     $stextfield ("label=message" "name=userName" "size=20")   

     $ssubmit ("label=pass it")   

     #end   

  </body>   

  </html>

when I call this velocity file I get the following error

java.lang.RuntimeException: org.apache.velocity.exception.ParseErrorException: Encountered "#end\n" at /velocityArea/ammaMessage.vm[line 24, column 5]   
Was expecting one of:   
    <EOF>    
    "(" ...   
    <RPAREN> ...   
    <ESCAPE_DIRECTIVE> ...   
    <SET_DIRECTIVE> ...   
    "##" ...   
    "\\\\" ...   
    "\\" ...   
    <TEXT> ...   
    "*#" ...   
    "*#" ...   
    <STRING_LITERAL> ...   
    <IF_DIRECTIVE> ...   
    <STOP_DIRECTIVE> ...   
    <INTEGER_LITERAL> ...   
    <FLOATING_POINT_LITERAL> ...   
    <WORD> ...   
    <BRACKETED_WORD> ...   
    <IDENTIFIER> ...   
    <DOT> ...   
    "{" ...   
    "}" ...   

    at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:858)   
    at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:809)   
    at org.apache.velocity.tools.view.VelocityViewServlet.getTemplate(VelocityViewServlet.java:287)   
    at org.apache.velocity.tools.view.VelocityViewServlet.handleRequest(VelocityViewServlet.java:248)   
    at org.apache.velocity.tools.view.VelocityViewServlet.doRequest(VelocityViewServlet.java:215)   
    at org.apache.velocity.tools.view.VelocityViewServlet.doGet(VelocityViewServlet.java:181)   
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)   
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)   
    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.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:73)   
    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:191)   
    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:293)   
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)   
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)   
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)   
    at java.lang.Thread.run(Thread.java:619)   
Caused by: org.apache.velocity.exception.ParseErrorException: Encountered "#end\n" at /velocityArea/ammaMessage.vm[line 24, column 5]   
Was expecting one of:   
    <EOF>    
    "(" ...   
    <RPAREN> ...   
    <ESCAPE_DIRECTIVE> ...   
    <SET_DIRECTIVE> ...   
    "##" ...   
    "\\\\" ...   
    "\\" ...   
    <TEXT> ...   
    "*#" ...   
    "*#" ...   
    <STRING_LITERAL> ...   
    <IF_DIRECTIVE> ...   
    <STOP_DIRECTIVE> ...   
    <INTEGER_LITERAL> ...   
    <FLOATING_POINT_LITERAL> ...   
    <WORD> ...   
    <BRACKETED_WORD> ...   
    <IDENTIFIER> ...   
    <DOT> ...   
    "{" ...   
    "}" ...   

    at org.apache.velocity.Template.process(Template.java:141)   
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:446)   
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)   
    at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)   
    at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:422)   
    at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:853)   
    ... 22 more

It seems the problem is near

 #end

tag ,

but I don't know how to solve this, waiting for your reply..

regards

T.Thamilvaanan

+1  A: 

Why do you need #end tag? You don't have a block to end. Just remove it.

END is used to end a block like in a loop,

#foreach( $item in $list )
    <li>$item</li>
#end
ZZ Coder
oldest debugging technique in the world, that is... keep removing the offending line until it stops bitchin' :)
skaffman
As they were mentioned here http://struts.apache.org/2.x/docs/velocity-tags.html"Some VM tags require an #end statement while others do not. The inconsistency arises from a limitation in Velocity where tags must declare if they are a block or inline tag up front. As such, by default all tags are inline except for a few key ones, such as the form tag."So obviouly I need #end tag ,and I also tried without that, then the tags were just ignored and printed as it is.
T.Thamilvaanan
Oh. I see what you are doing now. Struts tags are macros, which must be prefixed with #, not $.
ZZ Coder
A: 

I made a grate mistake

I was using

$ instead of #

i.e. $sform instead of #sform

I made the nessassary changes and tried again.............

But still getting the same error................

T.Thamilvaanan
A: 

Finally the problem solved

here

T.Thamilvaanan