You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Scott (JIRA)" <de...@velocity.apache.org> on 2011/06/30 17:13:28 UTC

[jira] [Updated] (VELOCITY-805) Unable to convert instances of two separate enums on a Velocity Template

     [ https://issues.apache.org/jira/browse/VELOCITY-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Scott updated VELOCITY-805:
---------------------------

    Attachment: Test.zip

Shows error state when deployed and running.

> Unable to convert instances of two separate enums on a Velocity Template
> ------------------------------------------------------------------------
>
>                 Key: VELOCITY-805
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-805
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.7
>         Environment: Tomcat 6, Spring 3.0.4
>            Reporter: Scott
>            Priority: Minor
>         Attachments: Test.zip
>
>
> I am unable to utilize the valueOf method on two separate instances of an enum - which share the same name.  The issue is that when the second valueOf method is called, it is invoked on the first enum which is accessed in the template.
> This can be tested by creating two enums with the same name in two separate classes.  Place these onto the context, and then try to utilize the valueOf method and you'll receive a stack trace stating that no value exists.  For example create two separate classes with an inner enum which both have the same name.  Add each enum onto the context, and then in a template attempt to access them in the following way: $enum1.valueOf("VAL1") $enum2.valueOf("SOME_OTHER_VAL").  This will not work.  Luckily you are able to do the following as a workaround: $enum1.valueOf($enum1, "VAL1") $enum2.valueOf($enum2, "SOME_OTHER_VAL")
> Stack trace below:
> java.lang.IllegalArgumentException: No enum const class org.velocity.testing.domain.User$Actions.MODIFY_NAME
> 	java.lang.Enum.valueOf(Enum.java:196)
> 	org.velocity.testing.domain.User$Actions.valueOf(User.java:1)
> 	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	java.lang.reflect.Method.invoke(Method.java:597)
> 	org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
> 	org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
> 	org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)
> 	org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
> 	org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:369)
> 	org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
> 	org.apache.velocity.Template.merge(Template.java:356)
> 	org.apache.velocity.Template.merge(Template.java:260)
> 	org.springframework.web.servlet.view.velocity.VelocityLayoutView.renderScreenContent(VelocityLayoutView.java:180)
> 	org.springframework.web.servlet.view.velocity.VelocityLayoutView.doRender(VelocityLayoutView.java:150)
> 	org.springframework.web.servlet.view.velocity.VelocityView.renderMergedTemplateModel(VelocityView.java:291)
> 	org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
> 	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
> 	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
> 	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
> 	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
> 	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
> 	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org