You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niral Trivedi <ni...@gmail.com> on 2008/04/03 06:06:39 UTC

issue

Hi All,

I am using Struts 2.0.11 on RAD7, Webspher 6.1, JDK 1.5.

I am trying to create radio buttons using a dynamic Map as below:

<s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
        <s:param name="Keep" value="john"/>
        <s:param name="Remove" value="doe"/>
</s:bean>


<td width="20%" style="background-color:#fffade; vertical-align:center">
        <s:radio name="keepRemove" list="keepRemoveRadioMap"  onclick=
"changeKeep1()" theme="simple"/>
</td>

But when I try to load the page, it is giving Freemaker Template exception
as below(I haven't pasted entire stack trace for readability) :
*
FreeMarker template error!*


Error on line 31, column 9 in template/simple/radiomap.ftl
stack.findString(parameters.listValue) is undefined.
It cannot be assigned to itemValue
The problematic instruction:
----------
==> assignment: itemValue=stack.findString(parameters.listValue) [on line
31, column 9 in template/simple/radiomap.ftl]
 in user-directive s.iterator [on line 23, column 1 in
template/simple/radiomap.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Error on line 31, column 9 in
template/simple/radiomap.ftl
stack.findString(parameters.listValue) is undefined.
It cannot be assigned to itemValue
        at freemarker.core.Assignment.accept(Assignment.java:111)
        at freemarker.core.Environment.visit(Environment.java:196)
        at freemarker.core.IfBlock.accept(IfBlock.java:82)
        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.visit(Environment.java:233)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
        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.UIBean.end(UIBean.java:484)
        at
org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:43)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_radio_1(_features_5F_form_5F_content.java:1806)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_if_12(_features_5F_form_5F_content.java:1847)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_iterator_1(_features_5F_form_5F_content.java:1956)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_if_2(_features_5F_form_5F_content.java:1994)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_if_1(_features_5F_form_5F_content.java:2031)
        at
com.ibm._jsp._features_5F_form_5F_content._jspx_meth_s_iterator_0(_features_5F_form_5F_content.java:3493)
        at
com.ibm._jsp._features_5F_form_5F_content._jspService(_features_5F_form_5F_content.java:273)
        at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:85)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


But If I change the value for value attribute in <s:param> tag to '01' or
'02' or something then it works fine and display 1 and 2 instead of '01' and
'02' for label. So, is this some bug in <s:radio> in Struts2? What is the
solution if I want to dynamically create Map and assign it to list attribute
of <s:radio> ?

Thanks a lot in advance for the help one more time..

Re: issue

Posted by Laurie Harper <la...@holoweb.net>.
Niral Trivedi wrote:
> Hi Dave,
> 
> Thanks for the reply. I've actually tried with #keepRemoveRadio as well but
> got same result. In fact, I got it working by putting "john" or "doe" as
> below for <s:param> property:
> 
> <s:param name="*Keep*" value="%{'john}"/>

That makes sense, since value="john" will try to evaluate 'john' as an 
expression (i.e. will look for it on the value stack) whereas 
value="%{'john'}" (or simply value="'john'") evaluates to a literal 
string. This is described in the Tag Syntax guide linked at the top of 
all the tag documentation pages:

http://struts.apache.org/2.0.11/docs/tag-syntax.html

[Hmm; that said, I just noticed that the 2.0.11 docs for s:param claim 
that the value attribute is *not* evaluated, which is inconsistent with 
what you're seeing; it could be that the documentation is in need of 
updating for that tag.]

> Moving ahead, now stuck with a different issue. Actually, I want to create
> name of the param dynamically by concatenating two strings. One is already a
> struts2 <s:set> property and other is a static value. For example, I want to
> do something like this:
> 
> Line 1: <s:set name="prop1" value="%{someActionProp}"/>
> 
> <s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
> *          <s:param name="%{prop1}Keep" value="%{prop1}john"/>
>          <s:param name="Remove" value="%{prop1}doe"/>
> * </s:bean>
> 
> But I could not get the lines in bold working. Do you have any idea how to
> concatenate two strings and assing it to a third variable? I tried
> <s:append> but that doesn't work either. Using that I can only iterate and
> print the values but cant assign to third variable.

Try <s:param name="%{prop1+'Keep'}" value="%{prop1+'john'}"/> instead 
(untested).

L.

> Thanks
> 
> On Thu, Apr 3, 2008 at 8:40 AM, Dave Newton <ne...@yahoo.com> wrote:
>> --- Niral Trivedi <ni...@gmail.com> wrote:
>>> I am using Struts 2.0.11 on RAD7, Webspher 6.1, JDK 1.5.
>> Hey, me too. My sympathies.
>>
>>> I am trying to create radio buttons using a dynamic Map as below:
>>>
>>> <s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
>>>         <s:param name="Keep" value="john"/>
>>>         <s:param name="Remove" value="doe"/>
>>> </s:bean>
>>>
>>> <td width="20%" style="background-color:#fffade; vertical-align:center">
>>>         <s:radio name="keepRemove" list="keepRemoveRadioMap"  onclick=
>>> "changeKeep1()" theme="simple"/>
>>> </td>
>>>
>>> But when I try to load the page, it is giving Freemaker Template
>> exception
>>> as below(I haven't pasted entire stack trace for readability) :
>> What happens if you use list="#keepRemoveRadioMap"?
>>
>> While I've never used the <s:bean...> tag, normally when you create an
>> object
>> in the OGNL context like that you need to refer to it with a leading "#"
>> meaning that it's a named object, not a property of an object on the value
>> stack.
>>
>> Dave
>>
>>
>> ---------------------------------------------------------------------
>> 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


Re: issue

Posted by Niral Trivedi <ni...@gmail.com>.
Hi Dave,

Thanks for the reply. I've actually tried with #keepRemoveRadio as well but
got same result. In fact, I got it working by putting "john" or "doe" as
below for <s:param> property:

<s:param name="*Keep*" value="%{'john}"/>

Moving ahead, now stuck with a different issue. Actually, I want to create
name of the param dynamically by concatenating two strings. One is already a
struts2 <s:set> property and other is a static value. For example, I want to
do something like this:

Line 1: <s:set name="prop1" value="%{someActionProp}"/>

<s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
*          <s:param name="%{prop1}Keep" value="%{prop1}john"/>
         <s:param name="Remove" value="%{prop1}doe"/>
* </s:bean>

But I could not get the lines in bold working. Do you have any idea how to
concatenate two strings and assing it to a third variable? I tried
<s:append> but that doesn't work either. Using that I can only iterate and
print the values but cant assign to third variable.

Thanks

On Thu, Apr 3, 2008 at 8:40 AM, Dave Newton <ne...@yahoo.com> wrote:

> --- Niral Trivedi <ni...@gmail.com> wrote:
> > I am using Struts 2.0.11 on RAD7, Webspher 6.1, JDK 1.5.
>
> Hey, me too. My sympathies.
>
> > I am trying to create radio buttons using a dynamic Map as below:
> >
> > <s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
> >         <s:param name="Keep" value="john"/>
> >         <s:param name="Remove" value="doe"/>
> > </s:bean>
> >
> > <td width="20%" style="background-color:#fffade; vertical-align:center">
> >         <s:radio name="keepRemove" list="keepRemoveRadioMap"  onclick=
> > "changeKeep1()" theme="simple"/>
> > </td>
> >
> > But when I try to load the page, it is giving Freemaker Template
> exception
> > as below(I haven't pasted entire stack trace for readability) :
>
> What happens if you use list="#keepRemoveRadioMap"?
>
> While I've never used the <s:bean...> tag, normally when you create an
> object
> in the OGNL context like that you need to refer to it with a leading "#"
> meaning that it's a named object, not a property of an object on the value
> stack.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: issue

Posted by Dave Newton <ne...@yahoo.com>.
--- Niral Trivedi <ni...@gmail.com> wrote:
> I am using Struts 2.0.11 on RAD7, Webspher 6.1, JDK 1.5.

Hey, me too. My sympathies.

> I am trying to create radio buttons using a dynamic Map as below:
> 
> <s:bean name="java.util.HashMap" id="keepRemoveRadioMap">
>         <s:param name="Keep" value="john"/>
>         <s:param name="Remove" value="doe"/>
> </s:bean>
> 
> <td width="20%" style="background-color:#fffade; vertical-align:center">
>         <s:radio name="keepRemove" list="keepRemoveRadioMap"  onclick=
> "changeKeep1()" theme="simple"/>
> </td>
> 
> But when I try to load the page, it is giving Freemaker Template exception
> as below(I haven't pasted entire stack trace for readability) :

What happens if you use list="#keepRemoveRadioMap"?

While I've never used the <s:bean...> tag, normally when you create an object
in the OGNL context like that you need to refer to it with a leading "#"
meaning that it's a named object, not a property of an object on the value
stack.

Dave


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