File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts and how to use MVC for it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and how to use MVC for it" Watch "Struts and how to use MVC for it" New topic

Struts and how to use MVC for it

Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Simply put, I am writing a small webapp where I get data from the database and need to display that in html form using struts. I am stuck about how to transmit data that I get from the model layer to the front-end. My service class (which is my bridge between my model and front end), returns to me a list of VO( value objects) returned to me as a result of a query. I have to use this list and somehow display this in a table format. What is the best way to do this ? Also, what tags in struts or how can I use tables in struts ? I could use some help. Thanks.

anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
according my knowledge this is not an intended use of struts.struts basically used to populate(automatically) server side form bean with values from input form without any extra work.but according to your specification you can put values retrieved from database in session and make execute of your action to forward to jsp page where you can display session fields in tabular form.
correct me if I am wrong
Jason Menard

Joined: Nov 09, 2000
Posts: 6450
If you want to know what tags are available, check out the Struts User Guide found on the Struts site.

What you are trying to do is typical of most Struts apps. In your Action, set your List of VOs to the request or session, whichever is appropriate. For example:

List vos = get your list of vos
request.setAttribute("vos", vos);

Let's assume your VO has the fields field1, field2, and field3. In your JSP, iterate over your List and display the data in the VO fields in an HTML table. For example:

your jsp

Hope that helps. You can find more information at the above link I posted, or if you're looking for a more extensive walkthough of Struts, you might want to take a look at the Struts Survival Guide.
Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
I will see if this works. Thanks for the info.
Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Thank you, Jason. That worked perfectly. I did not know that it would be this simple. My main concern before was that I had to bring the VO knowledge to the jsp page and I wasn't sure if that was a standard. Obviously, it is. I had another problem that I need to resolve in the same scenario. Once I get the resultset in the table format, is it possible that I can somehow create a link for one of the fields for each record. If the user clicks on that link, it should go to the details page of that record. Is that a possible scenario ? Would I be able to use the html:link tag ? I will definetely investigate a little harder but I would appreciate your input. Thanks for your help.
I agree. Here's the link:
subject: Struts and how to use MVC for it
It's not a secret anymore!