tags:

views:

723

answers:

2

This is going to be a little tricky to explain. I'm trying to write a tag to componentise a bunch of address fields, but I'm having trouble working out the ognl expression.

Expected usage:

member.address maps to an Address object (nothing too cleaver).

my tag (simplest version):

<%@taglib prefix="s" uri="/struts-tags" %>
<%@attribute name="name" required="true" rtexprvalue="true" type="java.lang.String" %>
<s:push value="%{#attr.name}">
    Address line 1:
    <s:property value="line1"/>
</s:push>

I think the issue is that <s:push value="%{#attr.name}"/> isn't actually pushing the result of member.address onto the stack it's just pushing a String of value 'member.address' instead.

+1  A: 

A little more research and a long time staring at the ognl documentation results in the following:

<%@taglib prefix="s" uri="/struts-tags" %>
<%@attribute name="name" required="true" rtexprvalue="true" type="java.lang.String" %>
<s:push value="%{(#attr.name)(#attr)}">
   Address line 1:
   <s:property value="line1"/>
</s:push>

Seems todo the trick.

Gareth Davis
A: 

Thank you so much!

This also resolves my issue related of passing Tiles attributes to Struts iterator tag. The link is here:

I don't if there is a way to link these questions between, but anyway... Thanks a lot! :)

jilt3d
no worries...feel free to use that upvote button :-)
Gareth Davis
Sure, but I can't. I don't have enough reputation. ;)
jilt3d