You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jukka Välimaa <va...@gmail.com> on 2008/06/06 13:47:22 UTC

Invoking action methods from jsp: parameter types

Hi all,

I'm trying to format a certain string property of an object differently
depending on the object state. For this, I'm trying to call an action method
from the jsp, like this:
<s:property value="%{ getFormattedIfDeleted( [0], [0].name ) }" />

My problem is the following: if I use my class type as the parameter type of
the first argument of the method, the jsp code never calls the action
method.

This version of method is called:
    public String getFormattedIfDeleted( Object modelObject, String
objectText ) {...}

This is not called:
    public String getFormattedIfDeleted( AbstractBaseObject modelObject,
String objectText ) {...}

The actual object I use as the parameter extends AbstractBaseObject. So it
should qualify just as well for both. I've confirmed that the object type is
the right one by printing it out in jsp.

What's more, if I use the first method, the object is no longer recognized
as its own type by instanceof,  modelObject instanceof AbstractBaseObject
evaluates as false.

I' quessing there is something esoteric in OGNL playing havoc here, but
that's about it. Any idea what's wrong? Thanks in advance.

Re: Invoking action methods from jsp: parameter types

Posted by Jukka Välimaa <va...@gmail.com>.
Well, I managed to solve this one. Ognl didn't actually pass the object
itself to the method, but rather an instance of
com.opensymphony.xwork2.util.CompoundRoot. I managed to get the object I
needed by using its peek() method.

On Fri, Jun 6, 2008 at 2:47 PM, Jukka Välimaa <va...@gmail.com>
wrote:

> Hi all,
>
> I'm trying to format a certain string property of an object differently
> depending on the object state. For this, I'm trying to call an action method
> from the jsp, like this:
> <s:property value="%{ getFormattedIfDeleted( [0], [0].name ) }" />
>
> My problem is the following: if I use my class type as the parameter type
> of the first argument of the method, the jsp code never calls the action
> method.
>
> This version of method is called:
>     public String getFormattedIfDeleted( Object modelObject, String
> objectText ) {...}
>
> This is not called:
>     public String getFormattedIfDeleted( AbstractBaseObject modelObject,
> String objectText ) {...}
>
> The actual object I use as the parameter extends AbstractBaseObject. So it
> should qualify just as well for both. I've confirmed that the object type is
> the right one by printing it out in jsp.
>
> What's more, if I use the first method, the object is no longer recognized
> as its own type by instanceof,  modelObject instanceof AbstractBaseObject
> evaluates as false.
>
> I' quessing there is something esoteric in OGNL playing havoc here, but
> that's about it. Any idea what's wrong? Thanks in advance.
>
>