*
The moose likes Struts and the fly likes Initializing bean in actionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Initializing bean in actionForm" Watch "Initializing bean in actionForm" New topic
Author

Initializing bean in actionForm

RaviSingh Kumar
Ranch Hand

Joined: Sep 04, 2007
Posts: 52
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
RaviSingh Kumar
Ranch Hand

Joined: Sep 04, 2007
Posts: 52
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Sep 04, 2007
Posts: 52
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Aug 10, 2006
Posts: 46
Looks like you need to have a look on the basic of struts...........that tooo ActionForm...
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initializing bean in actionForm