struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sven Grünewald <sven.gruenew...@bader-jene.de>
Subject Re: Accessing "id" bean-property (not tag attribute) in freemarker template
Date Tue, 30 Sep 2008 07:42:31 GMT
Thank you very much! This works!

Gabriel Belingueres schrieb:
> Inside the form.ftl, the stack.findValue(id') will find the form's id
> attribute, since the Form component is _already_ pushed into the
> stack. Hence, your action's id variable is shadowed by the form's id
> variable.
>
> What you would need then is ${action.id}
>
>
> 2008/9/29 Sven Grünewald <sven.gruenewald@bader-jene.de>:
>   
>> First of all: Thanks for your help!
>>
>> @Jan
>> I also thought about reserved word, but didn't find "id" on the list of
>> reserved freemarker-words in the docs. And I also think, that making "id" a
>> reserved word is a very bad idea if you want to use a framework also in
>> database-context ;-)
>>
>> @Gabriel Belingueres
>> My "id" is not realy stored in a bean. It is direktly accessible in the
>> Action through getId(), but if I try stack.findValue('id') there is the same
>> error:
>>
>> @Pascal:
>>
>> FreeMarker template error!
>>
>> Expression stack.findValue('id') is undefined on line 74, column 3 in
>> template/my/form.ftl.
>> The problematic instruction:
>> ----------
>> ==>  ${stack.findValue('id')} [on line 74, column 1 in template/my/form.ftl]
>> ----------
>>
>> Java backtrace for programmers:
>> ----------
>> freemarker.core.InvalidReferenceException: Expression stack.findValue('id')
>> is undefined on line 74, column 3 in template/my/form.ftl.
>>   at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
>>   at freemarker.core.Expression.getStringValue(Expression.java:118)
>>   at freemarker.core.Expression.getStringValue(Expression.java:93)
>>   at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
>>   at freemarker.core.Environment.visit(Environment.java:196)
>>   at freemarker.core.MixedContent.accept(MixedContent.java:92)
>>   at freemarker.core.Environment.visit(Environment.java:196)
>>   at freemarker.core.Environment.process(Environment.java:176)
>>   at freemarker.template.Template.process(Template.java:232)
>>   at
>> org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:168)
>>   at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:530)
>>   at
>> org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:58)
>>   at
>> org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:54)
>>   at
>> org.apache.jsp.gui.admin.profile.edit_jsp._jspx_meth_s_005fform_005f0(edit_jsp.java:456)
>>   at
>> org.apache.jsp.gui.admin.profile.edit_jsp._jspx_meth_tiles_005fputAttribute_005f1(edit_jsp.java:270)
>>   at
>> org.apache.jsp.gui.admin.profile.edit_jsp._jspx_meth_tiles_005finsertDefinition_005f0(edit_jsp.java:153)
>>   at
>> org.apache.jsp.gui.admin.profile.edit_jsp._jspService(edit_jsp.java:114)
>>   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.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:139)
>>   at
>> org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
>>   at
>> com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:44)
>>   at
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
>>   at
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
>>   at
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> de.baderjene.gta.security.AuthentificationInterceptor.intercept(AuthentificationInterceptor.java:41)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>   at
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>   at
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>   at
>> org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
>>   at
>> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
>>   at
>> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
>>   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:619)
>>
>>
>> Gabriel Belingueres schrieb:
>>     
>>> Did you tried using something like:
>>>
>>> <#assign myId = stack.findValue('bean.id')/>
>>>
>>>
>>> 2008/9/29 Sven Grünewald <sven.gruenewald@bader-jene.de>:
>>>
>>>       
>>>> I think it is stored on the value stack. As I said, I can get its other
>>>> properties directly via e.g. ${name}... Only ${id} is not working :-(
>>>>
>>>> Gabriel Belingueres schrieb:
>>>>
>>>>         
>>>>> Where is your bean stored? It is pushed into the value stack? is it in
>>>>> page? request? session?
>>>>>
>>>>> 2008/9/29 Sven Grünewald <sven.gruenewald@bader-jene.de>:
>>>>>
>>>>>
>>>>>           
>>>>>> Hi, can anybody help my?
>>>>>> I can't acces a bean property id  in a modified freemarker template.
>>>>>> I can access all other properties with simple OGNL expression but
not
>>>>>> if
>>>>>> they are called "id" or "ids"
>>>>>> If I add a getter: getMyId(){
>>>>>>  return getId();
>>>>>> } I can get it via ${myId} but not via ${id}.
>>>>>> I want to modify the form-tag to add the id of my entity in the URL
to
>>>>>> make
>>>>>> my actions bookmarkable etc. But I don't want to use GET. Only the
>>>>>> entity
>>>>>> id
>>>>>> should be shown in the URL e.g. .../shop/showItem.action?id=42.
>>>>>> Therefor
>>>>>> I
>>>>>> want to change the (rendered) form tag to <form ...
>>>>>> action=".../shop/showItem.action?id=42> but I can't acces my hidden
>>>>>> input
>>>>>> field "id" or the bean entry "id" but all other entries are accessable.
>>>>>> I am using struts 2.0.11 and have the same issue with 2.1
>>>>>>
>>>>>> Thanks in advance,
>>>>>>
>>>>>> Sven
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>   


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


Mime
View raw message