I'm making a webapp for booking conference rooms, using Struts 2.
Right now I need to create a table, with several columns and rows, in a jsp page.
It needs to be populated with an ArrayList, from an Action class (Java class), which contains the information about the bookings(Time, Date, Room number etc.)
How can I populate it with the info from my ArrayList?
If you know about any good tutorials, examples etc, I'd appreciate the links for them.
Here's all the code involved:
The table in the jsp is far from done, it's just a test to see how I can get values form a bean to be shown inside it.
Firstly, the business data (information about the bookings) should not be contained by a Struts Action class. This business data should be contained by a simple Plain Old Java Object class.
how I can access the ArrayList from my Action class
This is a pretty simple task.
The part that you seem to be missing is you need to put the ArrayList in the right scope and use the
Code in the JSP file will contain the iteration that will build the HTML table with the data content from the ArrayList.
Joined: Feb 13, 2009
I'm aware of the buisness data being in a POJO, and it is. I guess I didn't formulate my questiong correctly.
What I mean was that I want to access the values of the Array of POJO's (In this case Reservations), which is located in my Action class, not that I want to access the values of my Action class.
Thanks for pointing me into the right direction!
Joined: Feb 13, 2009
New question then..
useBean , as the name indicates, uses a bean. But how do I "get" the ArrayList into the jsp, through useBean? That should mean that I need to put the ArrayList in the bean, which sounds whacko to me. What am I missing..
Alia Huss wrote:New problem occurring, when I try to use the <jsp:useBean> tag I get this warning: "Unknown tag(jsp:useBean)" I guess it isn't finding the tag library, eh? Can barely find anything on the web about this. Do you have any idea about how to fix it?
'jsp' prefixed tags are standard tags from SUN for a JSP page, No need to import nor have to define any taglib for it.. So if its giving a warning, its ok. See whether its working on page or not
Normally you wouldn't put data like that into scope manually, you'd create an action property and use the <s:iterate> tag. You should probably spend some time looking at some of the S2 documentation wiki information, maybe grab Roughley's free Struts 2 book, and check out some of the example applications that come with Struts 2--it would answer a lot of your questions and save you some time.
If you *really* wanted to put it into scope you're probably implement RequestAware (or, less preferably, ServletRequestAware). You can't just randomly change the signature of a method and expect it to work; something has to *call* your methods and provide an argument. Even the most cursory examination of the documentation or the API would show that nothing in the framework would do this, and a reading of the FAQ would answer the question about how to access tings like the request, session, etc.