1

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

  • Which version you were using the id attribute is deprecated in Struts 2.1.x, and has been replaced by the var attribute. – MohanaRao SV Apr 28 '12 at 18:32
  • Tip, assume you don't need var (id as mentioned is deprecated) or status attributes in the iterator unless proven otherwise. Also if the collection just contains another collection List> then the inner iterator does not even need a name attribute (just an empty tag will do). Status and var have all kinds of uses but in general if you want to write record numbers or array indexes into the html then you will need status (although struts2 in general does not need indexes) and if you need to write properties of an outer iterator into the nested iterators then var is a good idea. – Quaternion Apr 28 '12 at 20:28

2 Answers2

0

Considering you have something like

List<ApplicationQuestionSetProgress> getQuestionProgressList(final int index)

Use this

<s:iterator var="qsp" value="questionProgessList[#row.index]" status="status"> 
mprabhat
  • 20,107
  • 7
  • 46
  • 63
0

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>
Quaternion
  • 10,380
  • 6
  • 51
  • 102
  • Thanks for all the help I have somethings to try out. I'm currently using struts 2.0.6, don't ask why just a requirement of the project. Nonetheless, I do have `getApplications` then I do a seperate db call to generate a list of `applicationQuestionSetProgress` because each application has 6 different `areas` with about ~20 questions in each, which I need to track progress on. So as I say one person may have many applications, – Mark Meiklejohn Apr 28 '12 at 22:09
  • but the progress is not attached to the application. Hence the List> so the outer list represents the potential number of applications so `index 0` would map to Application 1, index 1 would map to application 2 and so on so where the inner list contains the collection of all the area progress. – Mark Meiklejohn Apr 28 '12 at 22:10
  • But it sounds like each area has a "progress" if so the nesting would go another level deep... answer adjusted accordingly. – Quaternion Apr 28 '12 at 22:51
  • To help further it would be best to add code. If you could create minimal representations for application, areas and progress that would be very helpful (getters and setters to show relationships between them) along with the action and a statement as to what you are trying to display we can give concrete advice. – Quaternion Apr 28 '12 at 22:57