Struts 2 List of List access

1.3k Views Asked by At

I wonder if someone can help.

Background Architecture:

I have an application which contians many areas which have many specific questions, where these questions contian progress

So at a high-level view there can be many applications. A user is associated to maybe many applications.

So I have a list of applications and I can quite easliy iterate my way through and get its relevant details. But when it comes to accessing each specific area to get question progress for some reason it does not work out form me.

So here is logic I want:

for the applications

display its details

for each area(applicaitonId)

display each its completion progress

so to translate to struts I have this

<s:iterator id="app" value="appList" status="row">
<s:iterator id="qsp" value="questionProgessList[%{#row.index}]" status="status">

so applist is the list of all applications with its own getter/setter && questionSetProgress is defined by:

List<ApplicationQuestionSetProgress> getQuestionProgressList(final int index)

or List> getQuestionProgressList()

So trying in many ways to access the list has proved futile I have tried:

<s:iterator id="qsp" value="questionProgessList">
    <s:property />
</s:iterator>

with this:

List<List<ApplicationQuestionSetProgress>> getQuestionProgressList()

but no joy

I've also tried using the iterator index to call the method but it just does not work out.

List<ApplicationQuestionSetProgress> getQuestionProgressList(final int index)

i.e.

<s:iterator id="qsp" value="questionProgessList[%{#row.index}]" status="status"> or <s:iterator id="qsp" value="questionProgessList(%{#row.index})" status="status">

any hints or tips??

TIA

2

There are 2 best solutions below

4
On

You mentioned the following method:

List<List<ApplicationQuestionSetProgress>> getQuestionProgressList()

But you mentioned that the action needed to get a list of "applications" where each contained among its properties a list of "areas".

As such I would name that method:

List Applications getApplications(){
  return this.applications;
}

The form of a JSP to extract all properties would be:

<s:iterator value="applications">
   <s:property value=applicationsProperty1"/>
   <s:property value="applicationsProperty2"/>
   ...
   <s:iterator value="areas">
      <s:property value="areasProperty1"/>
      <s:property value="areasProperty2"/>
      ...
      <s:iterator value="progress">
         <s:property value="progressProperty1"/>
         <s:property value="progressProperty2"/>
         ...
      </s:iterator>
   </s:iterator>
</s:iterator>
0
On

Considering you have something like

List<ApplicationQuestionSetProgress> getQuestionProgressList(final int index)

Use this

<s:iterator var="qsp" value="questionProgessList[#row.index]" status="status">