Using pagination to display elements of an element in a table
I'm new to JSP, so bear with me.
I'm trying to make a JSP page that will display a table of some objects that I have fetched. Contained inside these objects is an array. In the table, I want there to be a hyperlink, or even a button, that will send the user to a page that will display the array contained inside the obj开发者_Python百科ect.
I currently have a for-loop going through the list of container objects (which hold the array), and that loop constructs the main table, I have it displaying other elements of the container object.
What technique should I use to have the table of container objects link to another page which has a table of the array? (which is in the container object) Each link from a container object needs to link to its contained array.
Your question is missing some basic information about the these containers and their origin. If they are coming from a database then the suggested route is to put in a link to another page passing the PK of the container object. This way, the second page will refetch the container and display its array.
if your container cannot be fetched a second time, I suggest then using javascript/jquery magic to display the array in the same page. This will result in larger HTML content but will avoid having to store the content in some sort of user's based cache.
Well, let me explain with a Order example. Orders is a collection and you want to list the entire collection in the mainpage. When a link is clicked you want to show the details pertaining to the particular order item.
In this case, you'd iterate through the collection using c:forEach
<c:forEach var="orderDetail" items="orders">
<a href="/myProj/orderDetail?orderId=${orderDetail.id}">Order Detail</a>
</c:forEach>
Each listing would have a link with a parameter that uniquely identifies the item as above.
Note here that the orderDetail is a servlet (or any controller). The request goes to the servlet, it reads the request parameter. With the orderId parameter it takes the associated order object, places it in request scope under a name, say orderDetailModel
and dispatches the request to orderDetailsPage.jsp The orderDetailsPage.jsp merely finds this orderDetailModel
object from request scope and displays it.
Like ${orderDetailModel.placedTime}
Hope this example helps.
精彩评论