You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by gentyjp <ge...@libertysurf.fr> on 2003/12/18 18:16:27 UTC

logic:iterate inside a logic:iterate ??

	
   Hi

  I'am a Struts newbie, sorry if it is a "classic" question.

  My question is about logic:iterate

  I have a vector of documents.
  In my application a document is a vector of LabelValueBean. I wish to 
write both the label and the value.

  I wish to write all my documents so I iterate through my vector of documents.
But after that how can I iterate through my vector of LabelValueBean ???

Basically here's what I want to do :

for_each_document
{
     for_each_LabelValueBean_in_the_current_document
     {
          write LabelValueBean.Label;
          write LabelValueBean.Value;
     }
}

    thanks for you help


   Genty Jean-Paul


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


Re: logic:iterate inside a logic:iterate ??

Posted by Jan Vervecken <Ja...@pandora.be>.
try something similar to this

(of course all the Java code to construct the lists should be in (or called by) a Struts Action class, so focus on the use of the logic:iterate tag)

--8<----loop.jsp------
<%@ page import="java.util.*" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%!
	public class Person
	{
		String fName = null;
		LinkedList fEmailList = new LinkedList();
		public String getName() { return fName; }
		public LinkedList getEmailList() { return fEmailList; }
	}
%>
<%
	LinkedList vPersonList = new LinkedList();
	Person vPerson = new Person();
	vPerson.fName = "Jan Vervecken";
	vPerson.fEmailList.add("Jan@a.be");
	vPerson.fEmailList.add("Jan@b.be");
	vPersonList.add(vPerson);
	vPerson = new Person();
	vPerson.fName = "Genty Jean-Paul";
	vPerson.fEmailList.add("Jean-Paul@a.be");
	vPerson.fEmailList.add("Jean-Paul@b.be");
	vPerson.fEmailList.add("Jean-Paul@c.be");
	vPersonList.add(vPerson);
	request.setAttribute("personList", vPersonList);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<HEAD>
	<TITLE>loop</TITLE>
</HEAD>
<BODY>
<H3>loop</H3>

<UL>
<logic:iterate id="person" name="personList">
	<LI>
		<bean:write name="person" property="name"/>
		<UL>
		<logic:iterate id="email" name="person" property="emailList">
			<LI>
				<bean:write name="email"/>
			</LI>
		</logic:iterate>
		</UL>
	</LI>
</logic:iterate>
</UL>

</BODY>
</html:html>
--8<----------

success
-Jan

*********** REPLY SEPARATOR  ***********

On 12/18/2003 at 6:16 PM gentyjp wrote:

>Hi
>
>  I'am a Struts newbie, sorry if it is a "classic" question.
>
>  My question is about logic:iterate
>
>  I have a vector of documents.
>  In my application a document is a vector of LabelValueBean. I wish to 
>write both the label and the value.
>
>  I wish to write all my documents so I iterate through my vector of
>documents.
>But after that how can I iterate through my vector of LabelValueBean ???
>
>Basically here's what I want to do :
>
>for_each_document
>{
>     for_each_LabelValueBean_in_the_current_document
>     {
>          write LabelValueBean.Label;
>          write LabelValueBean.Value;
>     }
>}
>
>    thanks for you help
>
>
>   Genty Jean-Paul
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org




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


RE: logic:iterate inside a logic:iterate ??

Posted by Robert Taylor <rt...@mulework.com>.
<logic:iterate id="document" name="formName" property="documents">
<logic:iterate id="lv" name="document" property="labelValueBeans">
<bean:write name="lv" property="label"/>
<bean:write name="lv" property="value"/>
</logic:iterate>
</logic:iterate>

You should probably use JSTL for this.

<c:forEach var="document" items="${formName.documents}">
<c:forEach var="lv" items="${document.lableValueBeans}">
<c:out value="${lv.label}"/>
<c:out value="${lv.value}"/>
</c:forEach>
</c:forEach>


> -----Original Message-----
> From: gentyjp [mailto:gentyjp@libertysurf.fr]
> Sent: Thursday, December 18, 2003 12:16 PM
> To: struts-user@jakarta.apache.org
> Subject: logic:iterate inside a logic:iterate ??
> 
> 
> 	
>    Hi
> 
>   I'am a Struts newbie, sorry if it is a "classic" question.
> 
>   My question is about logic:iterate
> 
>   I have a vector of documents.
>   In my application a document is a vector of LabelValueBean. I wish to 
> write both the label and the value.
> 
>   I wish to write all my documents so I iterate through my vector 
> of documents.
> But after that how can I iterate through my vector of LabelValueBean ???
> 
> Basically here's what I want to do :
> 
> for_each_document
> {
>      for_each_LabelValueBean_in_the_current_document
>      {
>           write LabelValueBean.Label;
>           write LabelValueBean.Value;
>      }
> }
> 
>     thanks for you help
> 
> 
>    Genty Jean-Paul
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

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