File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sandy Chatterjee
Ranch Hand
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Aniket Khadke
Greenhorn
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but where is the Resolution.

It's the same thing I have written.
 
Aniket Khadke
Greenhorn
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really puzzled
 
Aniket Khadke
Greenhorn
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 55
Hibernate Java Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks once again for your help. I have to do a quick research on sets to solve this issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic