Announcement Announcement Module
Collapse
No announcement yet.
Help me - Property 'exposeSpringMacroHelpers' is not writabl Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help me - Property 'exposeSpringMacroHelpers' is not writabl

    Hi, I'm Daniele Guarneri and I have a question for you?
    Below my configuration files and my Velocity template.

    *-servlet.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
    - Application context definition for "example" DispatcherServlet.
    -->

    <beans>

    <!-- ========================= VALIDATOR DEFINITIONS ========================= -->

    <!--
    - Validator for ExampleFormBean, implementing Spring's Validator interface.
    - Could also be defined in the root application context, if generic enough.
    -->
    <bean id="exampleValidator" class="example.ExampleValidator"/>

    <!-- ========================= CONTROLLER DEFINITIONS ========================= -->

    <!--
    - SimpleFormController definition, available at /example/myform
    - (according to the URL handler mapping definition above).
    - Uses the ExampleFormBeanValidator defined above.
    -->
    <bean id="exampleFormController" class="example.SimpleController">
    <property name="commandClass"><value>example.SimpleBean</value></property>
    <property name="commandName"><value>formData</value></property>
    <property name="validator"><ref local="exampleValidator"/></property>
    <property name="formView"><value>testForm</value></property>
    <property name="successView"><value>testForm</value></property>

    </bean>

    <!-- ========================= MAPPING DEFINITIONS ========================= -->

    <!--
    - Explicit URL handler mapping instead of default BeanNameUrlHandlerMapping.
    -->
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="urlMap">
    <map>
    <entry key="/formTest.form"><ref local="exampleFormController"/></entry>
    </map>
    </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
    <property name="basename"><value>views</value></property>
    </bean>

    </beans>

    velocity.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
    - Velocity resolver definition.
    -->

    <beans>
    <bean
    id="viewResolver" class="org.springframework.web.servlet.view.veloci ty.VelocityViewResolver">
    <property name="cache"><value>true</value></property>
    <property name="prefix"><value></value></property>
    <property name="suffix"><value>.vm</value></property>
    </bean>

    <!--
    This bean sets up the Velocity environment for us based on a root path for templates.
    Optionally, a properties file can be specified for more control over the Velocity
    environment, but the defaults are pretty sane for file based template loading.
    -->
    <bean
    id="velocityConfig"
    class="org.springframework.web.servlet.view.veloci ty.VelocityConfigurer" singleton="true">
    <property name="overrideLogging"><value>true</value></property>
    <property name="resourceLoaderPath"><value>/WEB-INF/templates</value></property>
    <property name="velocityProperties">
    <props>
    <prop key="velocimacro.library">lib/spring.vm,lib/macro.vm</prop>
    <prop key="velocimacro.library.autoreload">true</prop>
    <prop key="file.resource.loader.cache">false</prop>
    </props>
    </property>
    </bean>


    </beans>

    views.properties:
    testForm.class=org.springframework.web.servlet.vie w.velocity.VelocityView
    testForm.url=testFrom.vm
    testForm.exposeSpringMacroHelpers=true

    testForm.vm:
    <html>
    <body>
    #pippo()
    <form name="test" method="post" action="">
    #springFormInput("formData.name" "")<br>
    #springShowErrors("<br>" "")
    <input type="submit" value="ok"/>
    </form>
    </body>
    </html>

    what is this error??
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testForm' defined in null: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Property 'exposeSpringMacroHelpers' is not writable in bean class [org.springframework.web.servlet.view.velocity.Velo cityView]
    org.springframework.beans.factory.support.Abstract BeanFactory.applyPropertyValues(AbstractBeanFactor y.java:965)
    org.springframework.beans.factory.support.Abstract BeanFactory.populateBean(AbstractBeanFactory.java: 807)
    org.springframework.beans.factory.support.Abstract BeanFactory.createBean(AbstractBeanFactory.java:58 1)
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:184)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:159)
    org.springframework.web.servlet.view.ResourceBundl eViewResolver.initFactory(ResourceBundleViewResolv er.java:94)
    org.springframework.web.servlet.view.ResourceBundl eViewResolver.loadView(ResourceBundleViewResolver. java:75)
    org.springframework.web.servlet.view.AbstractCachi ngViewResolver.loadAndCacheView(AbstractCachingVie wResolver.java:77)
    org.springframework.web.servlet.view.AbstractCachi ngViewResolver.resolveViewName(AbstractCachingView Resolver.java:65)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:506)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:415)
    org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:313)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:299)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:763)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:712)
    org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:682)
    org.apache.jsp.index_jsp._jspService(index_jsp.jav a:42)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:133)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

    I'm working with spring framework version 1.1.2

    Help me, please :oops: !!

  • #2
    Sorry, this is my class:

    package example;

    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.bind.ServletRequestDataBin der;
    import org.springframework.validation.BindException;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class SimpleController extends SimpleFormController {

    protected ModelAndView processFormSubmission(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, BindException e) throws Exception {
    return new ModelAndView(getSuccessView());
    }

    protected Object formBackingObject (HttpServletRequest httpServletRequest) {
    SimpleBean sb = new SimpleBean();
    sb.setName("Daniele");
    return sb;
    }
    }

    Comment


    • #3
      views.properties:
      testForm.class=org.springframework.web.servlet.vie w.velocity.VelocityView
      testForm.url=testFrom.vm
      testForm.exposeSpringMacroHelpers=true
      VelocityView has no property named exposeSpringMacroHelpers. You must remove this line from views.properties.
      You can instead configure this property for VelocityViewResolver:
      Code:
      <bean 
      id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> 
      <property name="cache"><value>true</value></property> 
      <property name="prefix"><value></value></property> 
      <property name="suffix"><value>.vm</value></property> 
      <property name="exposeSpringMacroHelpers"><value>true</value></property> 
      </bean>
      HTH

      Comment


      • #4
        It's actually defined in the superclass, AbstractTemplateView, so setting this property on the VelocityView instance should work fine.

        Which version of Spring are you using Daniele? And how do you reference the "velocity.xml" file that you listed - this looks unusual.

        Regards,

        Comment


        • #5
          Thanks Davison, I'm using the last Spring version: 1.1.2
          And this is my web.xml (in red the code to reference the velocity.xml):


          <?xml version="1.0" encoding="ISO-8859-1"?>

          <!DOCTYPE web-app PUBLIC
          "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
          "http://java.sun.com/dtd/web-app_2_3.dtd">

          <!--
          - Web app deployment descriptor that just loads an "lele" DispatcherServlet
          - with a specific context.
          -
          - Depends on the following libraries in WEB-INF/lib:
          - * spring.jar
          - * commons-logging.jar
          - * log4j-1.2.x.jar
          -->

          <web-app>
          <!--
          - Key of the system property that should specify the root directory of this
          - web app. Applied by WebAppRootListener or Log4jConfigListener.
          -->
          <context-param>
          <param-name>webAppRootKey</param-name>
          <param-value>webapp.root</param-value>
          </context-param>

          <!--
          - Location of the Log4J config file, for initialization and refresh checks.
          - Applied by Log4jConfigListener.
          -->
          <context-param>
          <param-name>log4jConfigLocation</param-name>
          <param-value>/WEB-INF/classes/log4j.properties</param-value>
          </context-param>

          <!--
          - Location of the XML file that defines the root application context
          - Applied by ContextLoaderListener.
          -->
          <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/applicationContext.xml /WEB-INF/velocity.xml</param-value>
          </context-param>


          <!--
          - Configures Log4J for this web app.
          - As this context specifies a context-param "log4jConfigLocation", its file path
          - is used to load the Log4J configuration, including periodic refresh checks.
          -
          - Would fall back to default Log4J initialization (non-refreshing) if no special
          - context-params are given.
          -
          - Exports a "web app root key", i.e. a system property that specifies the root
          - directory of this web app, for usage in log file paths.
          - This web app specifies "example.root" (see log4j.properties file).
          -->
          <listener>
          <listener-class>org.springframework.web.util.Log4jConfigList ener</listener-class>
          </listener>

          <!--
          - Loads the root application context of this web app at startup,
          - by default from "/WEB-INF/applicationContext.xml".
          - Use WebApplicationContextUtils.getWebApplicationContex t(servletContext)
          - to access it anywhere in the web application, outside of the framework.
          -
          - The root context is the parent of all servlet-specific contexts.
          - This means that its beans are automatically available in these child contexts,
          - both for getBean(name) calls and (external) bean references.
          -->
          <listener>
          <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
          </listener>

          <!--
          - Servlet that dispatches request to registered handlers (Controller implementations).
          - Has its own application context, by default defined in "{servlet-name}-servlet.xml",
          - i.e. "example-servlet.xml".
          -
          - A web app can contain any number of such servlets.
          - Note that this web app does not have a shared root application context,
          - therefore the DispatcherServlet contexts do not have a common parent.
          -->
          <display-name>Spring Test Form</display-name>
          <servlet>
          <servlet-name>lele</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
          <load-on-startup>1</load-on-startup>
          </servlet>

          <!--
          - Maps the example dispatcher to /example/*. All handler mappings in
          - example-servlet.xml will by default be applied to this subpath.
          - If a mapping isn't a /* subpath, the handler mappings are considered
          - relative to the web app root.
          -
          - A single dispatcher could get mapped to multiple paths, like any servlet.
          -->
          <servlet-mapping>
          <servlet-name>lele</servlet-name>
          <url-pattern>*.form</url-pattern>
          </servlet-mapping>

          <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
          </welcome-file-list>

          </web-app>

          I see this way to reference velocity in Aurora project. I can put the code in velocity.xml also into applicationContext.xml or in *-servlet.xml, but for me this way is more clear.

          Irbouho, the same error there is also I set the property for VelocityViewResolver (At page 137 of spring documentation - chapter 13; 13.4.5 Bind support and form handling; it is explaned the way I used).

          Help me please.

          Comment


          • #6
            This is the error if I set property exposeSpringMacroHelpers for org.springframework.web.servlet.view.velocity.Velo cityViewResolver :cry:

            2004-11-20 11:23:13,506 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
            org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'viewResolver' defined in resource [/WEB-INF/velocity.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Property 'exposeSpringMacroHelpers' is not writable in bean class [org.springframework.web.servlet.view.velocity.Velo cityViewResolver]
            org.springframework.beans.NotWritablePropertyExcep tion: Property 'exposeSpringMacroHelpers' is not writable in bean class [org.springframework.web.servlet.view.velocity.Velo cityViewResolver]
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:509)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:566)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:595)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:582)
            at org.springframework.beans.factory.support.Abstract BeanFactory.applyPropertyValues(AbstractBeanFactor y.java:961)
            at org.springframework.beans.factory.support.Abstract BeanFactory.populateBean(AbstractBeanFactory.java: 807)
            at org.springframework.beans.factory.support.Abstract BeanFactory.createBean(AbstractBeanFactory.java:58 1)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:184)
            at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:159)
            at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
            at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:106)
            at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:136)
            at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:80)
            at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 32)
            at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3775)
            at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4257)
            at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:866)
            at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:850)
            at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:633)
            at org.apache.catalina.core.StandardHostDeployer.inst all(StandardHostDeployer.java:316)
            at org.apache.catalina.core.StandardHost.install(Stan dardHost.java:859)
            at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:723)
            at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:473)
            at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1002)
            at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:393)
            at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:166)
            at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1133)
            at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:816)
            at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1125)
            at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:518)
            at org.apache.catalina.core.StandardService.start(Sta ndardService.java:519)
            at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2343)
            at org.apache.catalina.startup.Catalina.start(Catalin a.java:581)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:297)
            at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:398)

            Comment


            • #7
              Ok, if I put the all in applicationContext.xml adn not use velocity.xml it work, now I have anather problem, but I must see better my code.

              See you later. Thanks....

              Comment

              Working...
              X