Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initializing bean in actionForm

 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to struts and i am making a dummy project using Struts. I have a AddRecord.jsp page in which there is two section
a) First section contains the fields related to recording info such as Recording ID, Recording Title, Format etc.
b) Second section contain fields for the number of tracks in a particular Recording.

I have made two beans RecordBean and TrackBean having setters and getters. I want to initialise these beans in my actionForm and also want to validate it.

Please let me know how to do declare and initialise the above beans in actionForm.

Thanks in advance
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviSingh Kumar wrote:I have made two beans RecordBean and TrackBean having setters and getters. I want to initialise these beans in my actionForm and also want to validate it.

I consider the beans you created are nothing but ActionForms, if not, I mean if you have done something like this

then you don't need to do that, simply extends ActionForm, like

RaviSingh Kumar wrote:
Please let me know how to do declare and initialise the above beans in actionForm.

Use constructor to initialize, (look for ActionForm#reset() method also) and extends ValidatorForm#validate() method for validation in action form.
 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

But for that i have to make the setters and getters for the all the fields. But i want that there must different bean for Record info and different for Track info.

So that when i am gng to update only the track info, i have to deal with trackBean.

I hope my requirement is clear.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviSingh Kumar wrote:But i want that there must different bean for Record info and different for Track info.

You can, any time, create two beans for record and track info.
 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, any time, create two beans for record and track info.


But for that extra piece of work is to be done.

Means i have to write setters and getters for all the fields that already defined in actionForm.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviSingh Kumar wrote:
You can, any time, create two beans for record and track info.

But for that extra piece of work is to be done.
Means i have to write setters and getters for all the fields that already defined in actionForm.

I'm not getting, If you have tow ActionForm/ValidatorForm, like this, then its good.
 
siddhu Math
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you need to have a look on the basic of struts...........that tooo ActionForm...
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're building hierarchy like, Track Info -> Record.
So either extends "Record" bean in TrackInfo Action form OR wrap TrackInfo bean into Record Action form

I hope this is what you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic