1

I have a class Message.java with two variables of same type Location.java called origin and destination

Message.java

public class Message{

    private Location origin;
    private Location destination;

//Getters and setters correctly defined   
}

Location.java

public class Location{

private String address;    
}

MessageAction.java

 public class MessageAction {

        private Message message;
       //Getters and setters correctly defined   
    }

I want to reuse code, so I have created a common JSP and pass the name of these variables by parameter. (Of course, the code is more complex, this is only a basic example, so it really helps me to reuse code)

message.jsp

<s:push value="message">
    <s:include value="/jsp/location.jsp">
        <s:param name="variableName" value="'origin'" />
    </s:include>
    <s:include value="/jsp/location.jsp">
        <s:param name="variableName" value="'destination'" />
    </s:include>
</push>

Here comes the problem, I don't know how to show the value of %{variableName}.address. I have tried several combinations and googled a while but I haven't found anything.

location.jsp

<s:set name="variableName">${param.variableName}</s:set>
<s:property value="%{%{variableName}.address}" />

If I write directly the names of the variables, I receive their value correctly, so the Action is setting them correctly.

<s:property value="origin.address" />
<s:property value="destination.address" />
Roman C
  • 47,329
  • 33
  • 60
  • 147
mardo
  • 303
  • 4
  • 10

1 Answers1

0

This is just wrong OGNL expression

%{%{variableName}.address}

if you want to reuse JSP as templete then you should use valid OGNL expression. Nevertheless passing parameter name is enormous since you will have complex OGNL to return the value of this parameter name.

You should also know that

Parameters are passed as request parameters, so use the ${param.ParamName} notation to access them. Do not use the property tag to access parameters in included files.

Roman C
  • 47,329
  • 33
  • 60
  • 147