This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
Hi, 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 Thanks Anupa
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:
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.
Joined: Sep 08, 2004
I will see if this works. Thanks for the info.
Joined: Sep 08, 2004
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.