You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Marcello Teodori (JIRA)" <ji...@apache.org> on 2007/10/25 21:19:39 UTC

[jira] Commented: (WW-2158) Incorrect binding of superclass fields when mapping from view (JSP) to Struts Actions

    [ https://issues.apache.org/struts/browse/WW-2158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42450 ] 

Marcello Teodori commented on WW-2158:
--------------------------------------

it works for me if I modify the model by making the base class (BaseType) not abstract, even if it would be better not to break the existing abstract base class design...

> Incorrect binding of superclass fields when mapping from view (JSP) to Struts Actions
> -------------------------------------------------------------------------------------
>
>                 Key: WW-2158
>                 URL: https://issues.apache.org/struts/browse/WW-2158
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.0.9
>            Reporter: Andres Montes
>             Fix For: 2.0.12
>
>
> When inherited classes are used as attributes of Struts Actions the binding of parameters from view to actions is not working properly. In fact, reflection is not able to map attributes from superclass, they are ignored, and mapped as not found on the retrieved result. For example:
> public abstract class BaseType implements Serializable {
>     Long id;
>     // getters and setters ...
> }
> public class TypeA extends BaseType implements Serializable {
>     String name;
>     // getters and setters ...
> }
> public class Item implements Serializable {
>     String name;
>     TypeA itemType;
>     // getters and setters ...
> }
> public class ItemCrudAction extends ActionSupport implements Preparable {
>      private Item myItem;
>      // getters and setters ...
>      // methods to populate data into view ...
> public void execute() {
>     // Retrieve attribute from View (JSP):
>    Item itemFromView = getMyItem(); // --> Here the compiler, through reflection, shows the following attributes:
>    // name (of type String) -correct-
>    // Relationship attribute TypeA with the following attributes:
>    //            From superclass BaseType: id (of type String[1] instead of Long) - incorrect-
>    // I guess this is because it can't find the attribute on the class
>    //           From class TypeA: name (of type String) - correct-
> }
> // item.jsp
> // ...
>    <s:textfield key="myitem.name" size="50" maxlength="2/>
>    // Combobox with values of type TypeA
>    // listOfValuesOfTypeA are filled from ItemCrudAction
>    <s:select key="myItem.itemType.id" list="listOfValuesOfTypeA" headerKey="-1" headerValue="-- Select value --" />

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.