?
Solved

struts questions. Please help

Posted on 2006-06-03
8
Medium Priority
?
217 Views
Last Modified: 2010-04-01
I am wondering how to code the struts ActionForm object if I want a page which will list out all the items from my database table, where I don't know how many records of this table have, let say maybe 10, maybe 100. And in the jsp page, I will have those item listed with a textfield beside it to let the users place order for this item. Then sent those ordered item to the backend.

My biggest is how do I code the ActionForm in order to get an unknown number of object, how should I do it? I really doubt about it. Please help. Thanks !
0
Comment
Question by:clo1
  • 5
  • 3
8 Comments
 
LVL 10

Expert Comment

by:radarsh
ID: 16828204
Hi clo1,

When the number of records is unknown, use pagination. Do not display all the records at once
as this might crash the server. Make the control go to an Action first which then populates
your ActionForm. Have an ArrayList in your ActionForm for this data.

________
radarsh
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16828365
It's a bad practice to code business logic in your ActionForms. Use the Action classes
which are specifically meant for this purpose.

________
radarsh
0
 
LVL 2

Author Comment

by:clo1
ID: 16829808
Hi all,
  Thanks. If I used pagination, let say display 10 items for each page, how do I record those 10 items for my form? I think it's not a good practice to create obj1.........obj10 in the actionForm, right? What can I do. Please help. thanks !
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:radarsh
ID: 16830246
Create an ArrayList object in your ActionForm and go on addeing obj1, obj2.... obj10 to this ArrayList.
In your JSP, iterate on this ArrayList and display all the elements.

________
radarsh
0
 
LVL 2

Author Comment

by:clo1
ID: 16830264
Hi Radarsh,
  Thanks, I'm kinda got the idea of how to do it, but is it when I have created 10 obj1...obj10 in my actionForm, and then I create the textfield obj1...obj10 in my jsp, and store them to one of the ArrayList in my actionForm, and when I retrieve the data from the action, I retrieve them from the actionForm's arraylist instead of the obj1...obj10? Thanks
0
 
LVL 10

Accepted Solution

by:
radarsh earned 200 total points
ID: 16830280
Ok i'll give you a pseudo code for that:

1. Hit the action.
2. MyForm myForm = (ActionForm)form;

ArrayList list = new ArrayList();
list.add(obj1);
list.add(obj2);
.....
....
myForm.setData(list);

.................
Your Form will be like this:

MyForm ...
{
    private ArrayList data;
    getter and setter for that.
..........
}

3. Forward to the JSP
4. In the JSP,
Use logic:iterate or c:forEach to iterate over the data ArrayList and
display the text fields.


________
radarsh
0
 
LVL 2

Author Comment

by:clo1
ID: 16830597
Wow, pretty clear. Excellent. I got it now. Thanks, and here are your points.
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16830765
:)

________
radarsh
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question