Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts ognl expression to evalulate the result of the expression

Tags:

jsp

struts2

ognl

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.

like image 977
Gareth Davis Avatar asked Jan 25 '26 22:01

Gareth Davis


1 Answers

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.

like image 73
Gareth Davis Avatar answered Jan 29 '26 11:01

Gareth Davis