File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How can I call the Action class inside <logic:iterator> tag in struts 1.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can I call the Action class inside <logic:iterator> tag in struts 1.3" Watch "How can I call the Action class inside <logic:iterator> tag in struts 1.3" New topic
Author

How can I call the Action class inside <logic:iterator> tag in struts 1.3

Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Hi ,

I have a Book table and a Categories table. The Categories table has a categoryNo which is a foreign key in the Books table. For each catogory there are a list of books.
I want to display the books in my jsp for each category.
In Struts2 I have done it by using <s:iterator> tag which iterates Categories object.
For each iteration I have fired an Action passing categoryNo as a request parameter using <s:action> tag. Which retrieves the Book List object for that particular category.

Now the problem is I am trying to implement the same using struts1 but I cannot find something equivalent to <s:action> tag.
Can anyone please help me.

Thanks,
Sandy



Take up one idea. Make that one idea your life; dream of it; think of it; live on that idea. Let the brain, the body, muscles, nerves, every part of your body be full of that idea, and just leave every other idea alone. This is the way to success.
Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29

You are trying to say you will click on category id i.e. hyperlink and then a action should be called to fetch books from that category? let me know this then I can try to solve your problem
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

You are trying to say you will click on category id i.e. hyperlink and then a action should be called to fetch books from that category?

Thanks for your reply.

categoryNo is not the hyperlink.
When the jsp is loaded the category object is also loaded.
Somewhat like this:

And my problem is I am not able to fire an Action in line number 2.

Regards,
Sandy
Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29

Sandy Chatterjee wrote:
You are trying to say you will click on category id i.e. hyperlink and then a action should be called to fetch books from that category?

Thanks for your reply.

categoryNo is not the hyperlink.
When the jsp is loaded the category object is also loaded.
Somewhat like this:

And my problem is I am not able to fire an Action in line number 2.


still not able to figure out your problem... what are you displaying on this jsp is list of categories or directly list of books ? abd if books then of which category? and if category then why do you need to fire action class at line 2? you can give a submit button and then trigger action.
Regards,
Sandy
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Sorry but where is the Resolution.

It's the same thing I have written.
Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29

Sandy Chatterjee wrote:Sorry but where is the Resolution.

It's the same thing I have written.


friend I am confused about your problems. Please answer the doubts.
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Sorry, I didn't see the last two lines.

what are you displaying on this jsp is list of categories or directly list of books ? abd if books then of which category? and if category then why do you need to fire action class at line 2? you can give a submit button and then trigger action.

I am displaying the Category. Say Networking is a category under which I have three books:

1) Network Fundamentals
2) Networking Concepts
3) Network Guide
Also say Language is a category under which I have two books:
1) Let us C.
2) Java for Beginners
Category is a table which contains cateoryId and categoryName
Book is a table which contains bookNo, bookName and categoryId as a foreign key.

Now in my jsp I am going to display heading as categoryName(say Networking) from Category table which will contain the bookName(i.e 1) Network Fundamentals 2) Networking Concepts 3) Network Guide).
Again for Language category 1) Let us C 2) Java for Beginners.
And the form will be populated automatically. So, I cannot use any Submit button to trigger the Action.

So, line number 1 populates the category object.
In line number 2 categoryId(say categoryId of 'Networking') will determine which books (i.e 1) Network Fundamentals 2) Networking Concepts 3) Network Guide) to fetch from the database and populate the books object.
Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29

So, line number 1 populates the category object.
In line number 2 categoryId(say categoryId of 'Networking') will determine which books (i.e 1) Network Fundamentals 2) Networking Concepts 3) Network Guide) to fetch from the database and populate the books object.



you cannot trigger action automatically at line 2. What I will suggest is fetch all the data first(both categories and books) and put them in collection (like Map). Now in jsp display the map...
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

you cannot trigger action automatically at line 2. What I will suggest is fetch all the data first(both categories and books) and put them in collection (like Map). Now in jsp display the map.

But it can be done in struts2.
The tag is <s:action>.
Anyways can you tell me the way to add two objects in a collection.
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Really puzzled
Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29

Do one thing in your form bean store categories plus a set of books of that category, that way you will have your bean something like:
String category;
Set<Book> books=new HashSet<Book>();//Book will be another class with book info. now you can store book objects in books set.

in your jsp get category and then iterate through books set using <logic tags>

do a little googling on set's. You will get lots of tutorials on sets. If problem still persists tell me.
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Thanks a lot for your help.
But as I told you for each Category there are a List of Books.
So, firstly I have to iterate through the Category List object. And then for each Category
I will have a set of books. As mentioned in the code.

My question is how can I get the above.

Aniket Khadke
Greenhorn

Joined: Jul 13, 2011
Posts: 29




second time iterate through books and books is in category. So in 2nd iterate statement put name as category or cat, as you have given id for category property... This should work..(I hope)
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Thanks once again for your help. I have to do a quick research on sets to solve this issue.
 
Don't get me started about those stupid light bulbs.
 
subject: How can I call the Action class inside <logic:iterator> tag in struts 1.3
 
Similar Threads
JPA: multiple many-to-many realationships between same two tables?
Struts2 questions
Admin User interface for 3.0
SelectOne inside DataTable
LastPostInfo is null on forum list