You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaarat Sharma <bh...@gmail.com> on 2009/05/21 18:28:50 UTC

Nested Struts2 iterator tags

Hi
I have two nested struts iterator tags.

The value for second iterator tag is property from the first iterator.

Something like this

<s:iterator value="stats">
        <th colspan="4">
            HOH Name <s:property value="hohName"/> | HOH DOB  <s:property
value="DOB"/>  | Project  <s:property value="developmentName"/>
        </th>
         <tr>
            <th class="cols">Member Name</th>
            <th class="cols">Member DOB</th>
            <th class="cols">Failed Verification Description</th>
        </tr>
      <s:iterator value="<s:property: value="memberDetails"/>"/>        <!--
 this is the second tag where 'memberDetails' is property from first
iterator tag. ofcourse this syntax is not correct-->
           .....
             .....
      <s:/iterator>
</s:iterator>

I would like to know what is the current syntax to achieve something like
this?

Re: Nested Struts2 iterator tags

Posted by Bhaarat Sharma <bh...@gmail.com>.
thanks!!

On Thu, May 21, 2009 at 2:29 PM, Martin Gainty <mg...@hotmail.com> wrote:

>
> //Assuming we have this Action
> //A Simple Action Class which demonstrates placing information in a Map
> public class GetEntryAction extends ActionSupport
> {
>    private ArrayList stats_list=new ArrayList(30); //a collection of stats
>    private class stats
>    {
>      private ArrayList entries_list=new ArrayList(30); // a collection of
> Entries
>      String StatusGroupName="StatusGroupName";
>      String StatusGroupID="StatusGroupID";
>    }
>    private class Entry
>    {
>                String HOHName;
>                public String getHOH Name()
>                {
>                        return HOHName;
>                }
>                public void setHOH Name(String HOHName)
>                {
>                        this.HOHName=HOHName;
>                }
>                String Price;
>                public String getPrice()
>                {
>                        return Price;
>                }
>                public void setPrice(String price)
>                {
>                        Price=price;
>                }
>                String OriginalValue;
>                public String getOriginalValue()
>                {
>                        return OriginalValue;
>                }
>                public void setOriginalValue(String str)
>                {
>                        OriginalValue=str;
>                }
>        }
>    public String execute() throws Exception
>    {
>
>                        Map session =
> ActionContext.getContext().getSession();
>
>              //construct new Uber stats class
>                        stats stats1=new stats();
>                        stats1.StatusGroupName=new
> String("StatusGroupName1");
>                        stats1.StatusGroupID=new String("StatusGroupID");
>
>                        //Name,Value,OriginalValue
> //construct the 1st entry
>                        Entry entry1=new Entry();
>                        entry1.setHOHName("ALL");
>                        entry1.setPrice("50.00");
>                        entry1.setOriginalValue("10.00");
> //put it into stats Map
>                        stats1.entries_list.add(entry1);
>
> //construct the second entry
>                        Entry entry2=new Entry();
>                        entry2.setHOHName("ALL");
>                        entry2.setPrice("50.00");
>                        entry2.setOriginalValue("10.00");
> //put it into entries Map
>                        stats1.entries_list.add(entry2);
>
>                        //put the stats class into stats_list
>                        stats_list.add(stats1);
>
>              //construct new Uber stats class
>                        stats stats2=new stats();
>                        stats2.StatusGroupName=new
> String("StatusGroupName2");
>                        stats2.StatusGroupID=new String("StatusGroupID2");
>
> //construct the 1st entry
>                        Entry entry2a=new Entry();
>                        entry2a.setHOHName("ALL");
>                        entry2a.setPrice("50.00");
>                        entry2a.setOriginalValue("10.00");
> //put it into stats Map
>                        stats2.entries_list.add(entry2a);
>
> //construct the second entry
>                        Entry entry2b=new Entry();
>                        entry2b.setHOHName("ALL");
>                        entry2b.setPrice("50.00");
>                        entry2b.setOriginalValue("10.00");
> //put it into entries Map
>                        stats2.entries_list.add(entry2b);
>
>                        session.put("stats_list",stats_list);
> //All of the information you require is now in the map which is now in the
> Session
>                        return SUCCESS;
>    }
> }
>
> <s:iterator value="#session.stats_list" status="statsStatus">
>     <tr class="<s:if test="#statsStatus.odd == true
> ">odd</s:if><s:else>even</s:else>">
>         <td><s:property value="name" /></td>
>         <td><s:property value="description" /></td>
>         <td>
>             <!-- notice the statsStatus.indexis used to refer to iterate
> from -->
>             <s:iterator
> value="#session.stats_list.entries_list('#statsStatus.index')"
> status="userStatus">
>
>                 <!-- display HOHName for anything other than 0 entry -->
>                 <s:property value="HOHName" /><s:if
> test="!#userStatus.index">,</s:if>
>
>             </s:iterator>
>         </td>
>     </tr>
>  </s:iterator
> HTH
> Martin Gainty
> ______________________________________________
> Jogi és Bizalmassági kinyilatkoztatás/Verzicht und
> Vertraulichkeitanmerkung/Note de déni et de confidentialité
>  Ez az
> üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
> jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
> készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
> semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
> könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
> ezen üzenet tartalma miatt.
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le
> destinataire prévu, nous te demandons avec bonté que pour satisfaire
> informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie
> de ceci est interdite. Ce message sert à l'information seulement et n'aura
> pas n'importe quel effet légalement obligatoire. Étant donné que les email
> peuvent facilement être sujets à la manipulation, nous ne pouvons accepter
> aucune responsabilité pour le contenu fourni.
>
>
>
>
> > Date: Thu, 21 May 2009 12:28:50 -0400
> > Subject: Nested Struts2 iterator tags
> > From: bhaarat.s@gmail.com
> > To: user@struts.apache.org
> >
> > Hi
> > I have two nested struts iterator tags.
> >
> > The value for second iterator tag is property from the first iterator.
> >
> > Something like this
> >
> > <s:iterator value="stats">
> >         <th colspan="4">
> >             HOH Name <s:property value="hohName"/> | HOH DOB  <s:property
> > value="DOB"/>  | Project  <s:property value="developmentName"/>
> >         </th>
> >          <tr>
> >             <th class="cols">Member Name</th>
> >             <th class="cols">Member DOB</th>
> >             <th class="cols">Failed Verification Description</th>
> >         </tr>
> >       <s:iterator value="<s:property: value="memberDetails"/>"/>
>  <!--
> >  this is the second tag where 'memberDetails' is property from first
> > iterator tag. ofcourse this syntax is not correct-->
> >            .....
> >              .....
> >       <s:/iterator>
> > </s:iterator>
> >
> > I would like to know what is the current syntax to achieve something like
> > this?
>
> _________________________________________________________________
> Hotmail® goes with you.
>
> http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=TXT_TAGLM_WL_HM_Tutorial_Mobile1_052009
>

RE: Nested Struts2 iterator tags

Posted by Martin Gainty <mg...@hotmail.com>.
//Assuming we have this Action
//A Simple Action Class which demonstrates placing information in a Map
public class GetEntryAction extends ActionSupport
{
    private ArrayList stats_list=new ArrayList(30); //a collection of stats
    private class stats
    {
      private ArrayList entries_list=new ArrayList(30); // a collection of Entries
      String StatusGroupName="StatusGroupName";
      String StatusGroupID="StatusGroupID";
    }
    private class Entry
    {
		String HOHName;
		public String getHOH Name()
		{
			return HOHName;
		}
		public void setHOH Name(String HOHName)
		{
			this.HOHName=HOHName;
		}
		String Price;
		public String getPrice()
		{
			return Price;
		}
		public void setPrice(String price)
		{
			Price=price;
		}
		String OriginalValue;
		public String getOriginalValue()
		{
			return OriginalValue;
		}
		public void setOriginalValue(String str)
		{
			OriginalValue=str;
		}
	}
    public String execute() throws Exception
    {
               
  			Map session = ActionContext.getContext().getSession();

              //construct new Uber stats class
                        stats stats1=new stats();
                        stats1.StatusGroupName=new String("StatusGroupName1");
                        stats1.StatusGroupID=new String("StatusGroupID");
  			
  			//Name,Value,OriginalValue
//construct the 1st entry
  			Entry entry1=new Entry();
  			entry1.setHOHName("ALL");
  			entry1.setPrice("50.00");
  			entry1.setOriginalValue("10.00");   
//put it into stats Map
                        stats1.entries_list.add(entry1);

//construct the second entry
  			Entry entry2=new Entry();
  			entry2.setHOHName("ALL");
  			entry2.setPrice("50.00");
  			entry2.setOriginalValue("10.00");   
//put it into entries Map
                        stats1.entries_list.add(entry2);

                        //put the stats class into stats_list
                        stats_list.add(stats1);

              //construct new Uber stats class
                        stats stats2=new stats();
                        stats2.StatusGroupName=new String("StatusGroupName2");
                        stats2.StatusGroupID=new String("StatusGroupID2");
                      			
//construct the 1st entry
  			Entry entry2a=new Entry();
  			entry2a.setHOHName("ALL");
  			entry2a.setPrice("50.00");
  			entry2a.setOriginalValue("10.00");   
//put it into stats Map
                        stats2.entries_list.add(entry2a);

//construct the second entry
  			Entry entry2b=new Entry();
  			entry2b.setHOHName("ALL");
  			entry2b.setPrice("50.00");
  			entry2b.setOriginalValue("10.00");   
//put it into entries Map
                        stats2.entries_list.add(entry2b);

          		session.put("stats_list",stats_list);
//All of the information you require is now in the map which is now in the Session
 			return SUCCESS;
    }
}

<s:iterator value="#session.stats_list" status="statsStatus">
     <tr class="<s:if test="#statsStatus.odd == true ">odd</s:if><s:else>even</s:else>">
         <td><s:property value="name" /></td>
         <td><s:property value="description" /></td>
         <td>
             <!-- notice the statsStatus.indexis used to refer to iterate from -->
             <s:iterator value="#session.stats_list.entries_list('#statsStatus.index')" status="userStatus">

                 <!-- display HOHName for anything other than 0 entry --> 
                 <s:property value="HOHName" /><s:if test="!#userStatus.index">,</s:if>

             </s:iterator>
         </td>
     </tr>
 </s:iterator
HTH
Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Thu, 21 May 2009 12:28:50 -0400
> Subject: Nested Struts2 iterator tags
> From: bhaarat.s@gmail.com
> To: user@struts.apache.org
> 
> Hi
> I have two nested struts iterator tags.
> 
> The value for second iterator tag is property from the first iterator.
> 
> Something like this
> 
> <s:iterator value="stats">
>         <th colspan="4">
>             HOH Name <s:property value="hohName"/> | HOH DOB  <s:property
> value="DOB"/>  | Project  <s:property value="developmentName"/>
>         </th>
>          <tr>
>             <th class="cols">Member Name</th>
>             <th class="cols">Member DOB</th>
>             <th class="cols">Failed Verification Description</th>
>         </tr>
>       <s:iterator value="<s:property: value="memberDetails"/>"/>        <!--
>  this is the second tag where 'memberDetails' is property from first
> iterator tag. ofcourse this syntax is not correct-->
>            .....
>              .....
>       <s:/iterator>
> </s:iterator>
> 
> I would like to know what is the current syntax to achieve something like
> this?

_________________________________________________________________
Hotmail® goes with you. 
http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=TXT_TAGLM_WL_HM_Tutorial_Mobile1_052009

Re: Nested Struts2 iterator tags

Posted by Bhaarat Sharma <bh...@gmail.com>.
nevermind...
this works:  <s:iterator value="%{memberDetails}">

On Thu, May 21, 2009 at 12:28 PM, Bhaarat Sharma <bh...@gmail.com>wrote:

> Hi
> I have two nested struts iterator tags.
>
> The value for second iterator tag is property from the first iterator.
>
> Something like this
>
> <s:iterator value="stats">
>         <th colspan="4">
>             HOH Name <s:property value="hohName"/> | HOH DOB  <s:property
> value="DOB"/>  | Project  <s:property value="developmentName"/>
>         </th>
>          <tr>
>             <th class="cols">Member Name</th>
>             <th class="cols">Member DOB</th>
>             <th class="cols">Failed Verification Description</th>
>         </tr>
>       <s:iterator value="<s:property: value="memberDetails"/>"/>
>  <!--  this is the second tag where 'memberDetails' is property from first
> iterator tag. ofcourse this syntax is not correct-->
>            .....
>              .....
>       <s:/iterator>
> </s:iterator>
>
> I would like to know what is the current syntax to achieve something like
> this?
>
>

Re: Nested Struts2 iterator tags

Posted by XCoder Nitin <ni...@gmail.com>.
This is how the JSP code will look like:

        <s:form action="saveaction" >
            <s:iterator value="lstBean" id="lstBean" status="outerStat">
                <s:textfield value="%{name}"
name="lstBean[%{#outerStat.index}].name"/>
                <s:textfield value="%{amt}"
name="lstBean[%{#outerStat.index}].amt"/>
                <s:textfield value="%{id}"
name="lstBean[%{#outerStat.index}].id"/>
                <s:iterator value="%{lstString}" status="myStat">
                    <s:textfield
name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
                </s:iterator>
            </s:iterator>
            <s:submit value="Click me to submit lstBean"/>
        </s:form>


Following is the bean(XBean) whose List is used in the JSP:

    public class XBean
    {    
    private ArrayList<String> lstString=new ArrayList<String>();
    private String name;
    private Double amt;
    private Integer id;
    //Getters and setters of fields
    }

Now you can simply have a field lstBean with setters in your submitting
action (saveaction) and hey you are done.
-- 
View this message in context: http://old.nabble.com/Nested-Struts2-iterator-tags-tp23656304p30936629.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Nested Struts2 iterator tags

Posted by XCoder Nitin <ni...@gmail.com>.
This is how the JSP code will look like:

        <s:form action="saveaction" >
            <s:iterator value="lstBean" id="lstBean" status="outerStat">
                <s:textfield value="%{name}"
name="lstBean[%{#outerStat.index}].name"/>
                <s:textfield value="%{amt}"
name="lstBean[%{#outerStat.index}].amt"/>
                <s:textfield value="%{id}"
name="lstBean[%{#outerStat.index}].id"/>
                <s:iterator value="%{lstString}" status="myStat">
                    <s:textfield
name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
                </s:iterator>
            </s:iterator>
            <s:submit value="Click me to submit lstBean"/>
        </s:form>


Following is the bean(XBean) whose List is used in the JSP:

    public class XBean
    {    
    private ArrayList<String> lstString=new ArrayList<String>();
    private String name;
    private Double amt;
    private Integer id;
    //Getters and setters of fields
    }

Now you can simply have a field lstBean with setters in your submitting
action (saveaction) and hey you are done.
-- 
View this message in context: http://old.nabble.com/Nested-Struts2-iterator-tags-tp23656304p30936628.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org