You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bouvet Konsulent <bo...@statnett.no> on 2005/11/21 13:08:02 UTC
nested Sets
hello,
I am using Struts 1.2.7 together with Hibernate 3.0. My datamodel is not
too complex, but one of my Struts-forms needs to fetch data from several
tables. My tables are called A, B and C. One A contains many B's and one
B contains many C's. In Struts, I would need to display data from all
three tables and also be able to save changes. How would I go about to
do this? In MyForm.java, which primarily models A, I have getters and
setters for all of A columns, like name, id etc. But what about B and C?
I guess it would not be possible to have these as Sets in MyForm.java? I
could maybe model B as an ArrayList and use <nested:iterate> and
<nested:text> in my jsp, but then again: what about C?
To just display the data would not be a big problem, but when I want to
make changes to the data in e.g. C, I would also need some setters for
the properties. Really don't know how to do this...
Any ideas would be highly appreciated!
cheers,
pj
Re: nested Sets
Posted by Danny Lee <ha...@yahoo.de>.
You just have to organize something like
seto of B's in yur A and set of C's in your B.
This has to be done per Hibernate (<bag>'s in hibernate.cfg.xml and List
getters setters in DAO Classes).
When you've done this, you can iterate all the attributes without big
prob's. After user submiting new values, struts will change the beans in
the ActionForm, where your tables-DAO are stored. After that you have to
call your Hibernate persistance manager and persist the changes.
Cheers
Danny
Bouvet Konsulent schrieb:
> hello,
> I am using Struts 1.2.7 together with Hibernate 3.0. My datamodel is not
> too complex, but one of my Struts-forms needs to fetch data from several
> tables. My tables are called A, B and C. One A contains many B's and one
> B contains many C's. In Struts, I would need to display data from all
> three tables and also be able to save changes. How would I go about to
> do this? In MyForm.java, which primarily models A, I have getters and
> setters for all of A columns, like name, id etc. But what about B and C?
> I guess it would not be possible to have these as Sets in MyForm.java? I
> could maybe model B as an ArrayList and use <nested:iterate> and
> <nested:text> in my jsp, but then again: what about C?
>
> To just display the data would not be a big problem, but when I want to
> make changes to the data in e.g. C, I would also need some setters for
> the properties. Really don't know how to do this...
>
> Any ideas would be highly appreciated!
>
> cheers,
> pj
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: nested Sets
Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Are you positive that your action has done a Hibernate query that returns a set of data into your POJO so that your problem is only the nested iteration? Are you positive your beans are being saved in a scope (most likely request or session, not application), etc. ?
Regards,
David
-----Original Message-----
From: Bouvet Konsulent [mailto:maillist@roomity.com]
Sent: Monday, November 21, 2005 9:46 AM
To: user@struts.apache.org
Subject: Re:nested Sets
thanks for the answer! I have tried to follow your suggestions, but I can not get Struts to populate my Hibernate POJOs... This is the code I am using: MyForm.java: private Set Bs; //this also has a getter and setter B.java (which is a Hibernate-generated POJO) contains e.g. the following property private String formulaPart; //this also has a getter and setter my A.hbm.xml contains the following: my B.hbm.xml contains the following: and in my jsp I try to do the following: when submitting the form, the value in B (formulaPart) is not updated. Any ideas what I'm doing wrong? Thanks for your help! cheers, pj Danny wrote: >You just have to organize something like >seto of B's in yur A and set of C's in your B. >This has to be done per Hibernate ( 's in hibernate.cfg.xml and List >getters setters in DAO Classes). >When you've done this, you can iterate all the attributes without big >prob's. After user submiting new values, struts will change the beans in >the ActionForm, where your tables-DAO are stored. After that you have to >call your Hibernate persistance manager and persist the changes.
Broadband interface (RIA) + mail box saftey = http://Struts_User_List.roomity.com
*Your* clubs, no sign up to read, ad supported; try broadband internet.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re:nested Sets
Posted by Bouvet Konsulent <ma...@roomity.com>.
thanks for the answer! I have tried to follow your suggestions, but I can not get Struts to populate my Hibernate POJOs... This is the code I am using: MyForm.java: private Set Bs; //this also has a getter and setter B.java (which is a Hibernate-generated POJO) contains e.g. the following property private String formulaPart; //this also has a getter and setter my A.hbm.xml contains the following: my B.hbm.xml contains the following: and in my jsp I try to do the following: when submitting the form, the value in B (formulaPart) is not updated. Any ideas what I'm doing wrong? Thanks for your help! cheers, pj Danny wrote: >You just have to organize something like >seto of B's in yur A and set of C's in your B. >This has to be done per Hibernate ( 's in hibernate.cfg.xml and List >getters setters in DAO Classes). >When you've done this, you can iterate all the attributes without big >prob's. After user submiting new values, struts will change the beans in >the ActionForm, where your tables-DAO are stored. After that you have to >call your Hibernate persistance manager and persist the changes.
Broadband interface (RIA) + mail box saftey = http://Struts_User_List.roomity.com
*Your* clubs, no sign up to read, ad supported; try broadband internet.