[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: Struts2 POJO population from URL
From:       Maurizio Cucchiara <maurizio.cucchiara () gmail ! com>
Date:       2011-08-28 8:02:43
Message-ID: CANrzj0kJxiDvj5HOTz1yDTqvPDfmx9VwyTMhnh=-YfqT7o8aXQ () mail ! gmail ! com
[Download RAW message or body]

In the same way, try to initialize the Ghi and Def object before the
action is invoked.
Maurizio Cucchiara



On 28 August 2011 07:45, James Jithin <james4u@gmail.com> wrote:
> I have a Java Object with many other nested Objects and lists of Objects.
> When the request arrives from the client, I see that the Object is populated
> only to a few levels. Is there any configuration that sets this is Struts 2?
> Here is my example.
>
>    class MyActionClass extends ActionSupport {
>        private Abc abc;
>        public Abc getAbc() {
>            return abc;
>        }
>        public void setAbc(Abc abc) {
>            this.abc = abc;
>        }
>        public String populate() {
>            MyService myService = new MyService();
>            abc = myService.getMyAbc();
>            return SUCCESS;
>        }
>        public String update() {
>            MyService myService = new MyService();
>            myService.updateAbc(abc);
>            return SUCCESS;
>        }
>    }
>
>    class Abc {
>        private List<Def> defList;
>        private Ghi ghi;
>        public void setDefList(List<Def> defList) {
>            this.defList = defList;
>        }
>        public List<Def> getDefList(){
>            return defList;
>        }
>        public void setGhi(Ghi ghi) {
>            this.ghi = ghi;
>        }
>        public Ghi getGhi() {
>            return ghi;
>        }
>    }
>
>    class Def {
>        private String name;
>        private long id;
>        public String getName() {
>            return name;
>        }
>        public void setName(String name) {
>            this.name = name;
>        }
>        public long getId() {
>            return id;
>        }
>        public void setId(long id) {
>            this.id = id;
>        }
>    }
>
>    class Ghi {
>        private List<Def> defList;
>        private String ghiName;
>
>        public void setDefList(List<Def> defList) {
>            this.defList = defList;
>        }
>        public List<Def> getDefList() {
>            return defList;
>        }
>        public void setGhiName(String ghiName) {
>            this.ghiName = ghiName;
>        }
>        public String getGhiName() {
>            return ghiName;
>        }
>    }
>
> When I call the `populate` method and when send to the jsp, the iteration
> happens good with all the elements. But, when I try to update, i.e. when
> then form is submitted, the `update()` method is called, but the instance
> variable abc does not get populated completely.
>
> I have seen the url which is passed and everything seems to be fine. Let me
> tell you what happens. The url will be something like (splitting with line
> break for easy understanding here),
>
>    &abc.defList[0].name=alex
>    &abc.defList[0].id=1
>    &abc.defList[1].name=bobby
>    &abc.defList[1].id=2
>    &abc.ghi.ghiName=GHINAME
>    &abc.ghi.defList[0].name=Jack
>    &abc.ghi.defList[0].id=1
>    &abc.ghi.defList[1].name=Jill
>    &abc.ghi.defList[1].id=2
>
> In this case, the `defList` inside `abc` and `ghi.ghiName` in `abc` are
> populated with no issues. But the `defList` of `abc.ghi` is not populated.
> Is this a common behavior of Struts 2? Is ther any means by which this can
> be overridden?
>
> - Jim
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic