Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Many to one Mapping in a ActionForm

 
Pradeep Arun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Thats works for me.

Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic