aspose file tools*
The moose likes Struts and the fly likes Many to one Mapping in a ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Many to one Mapping in a ActionForm" Watch "Many to one Mapping in a ActionForm" New topic
Author

Many to one Mapping in a ActionForm

Pradeep Arun
Greenhorn

Joined: Dec 28, 2007
Posts: 19
Hi,

I have a jsp where in i am getting percentage of mark details in first year, second year, thrid year etc., of graduation. Each one is displayed in a single row. Example

Year Percentage
2008 80%
2009 100%

The above Year and percentage is mapped to a column called year and percentage in database. year and percentage are text box in the jsp

Year is dynamic. Meaning, while rendering the year only i will know how many years we have. My ActionForm has a two properties as below

class PercentageForm extends ActionForm
{
String year;
String percentage;

}

So my question is, how can we map the multiple year, percentage to a single ActionForm in struts?

Regards,
APK
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Pradeep,

Please check your private messages for a message regarding an important administrative matter.

Regarding your question:

Make the class with year and percentage properties a regular JavaBean rather than an ActionForm and call it something like StudentMarksBean. Then in your ActionForm, create a property of type java.util.List which contains a list of StudentMarksBeans. You can then use the logic:iterate and bean:write tags in your JSP to iterate over this list of beans and display their contents.
[ July 17, 2008: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

Make the element a String[] and to display on the page you can use a Struts custom tag (loop) or make the Year a drop down?

Cheers,
Raj.
Pradeep Arun
Greenhorn

Joined: Dec 28, 2007
Posts: 19
Hi,

Thanks for the reply.
My question is not about rendering the form data, but when i submit the jsp, how can i map the unknown number of text fields to the Action Form property.

Many Thanks,
Pradeep
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order to do this, you will need to use "indexed properties". See question 15 of our FAQ for details on how to do this, along with a working example.
Pradeep Arun
Greenhorn

Joined: Dec 28, 2007
Posts: 19
Yes. Thats works for me.

Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Many to one Mapping in a ActionForm