You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Britske <gb...@gmail.com> on 2008/03/27 19:24:51 UTC

T5: nested loops don't work (can't figure this one out)

Hi, 

I'm breaking my head on this one. 
I have  2 nested loops where the value of the outer loop is used as the
source of the inner loop.

The problem is that getCurPhotoAsThumb() is never called (as noticed by
debugging) thus nothing is rendered. 
I've made sure that getCurThumbSublist() has at least 1 element. 

Anyone?

I've supplied the relative template and class-parts:

TEMPLATE>
---------------------
<t:loop source="listOfThumbSubLists" value="curThumbSublist">
  <div id="${currentThumbContainerId}" class="thumbcontainer">
       <t:loop source="curThumbSublist" value="curPhotoAsThumb">
           ${curPhotoAsThumb.url}
      	</t:loop>
   </div>
 </t:loop>


CLASS> 
---------------
private int maxListsize = 6;
private List<Photo> curThumbSublist;
private Photo curPhotoAsThumb;
private int curListCounter = 0;
	
	public List<Photo> getCurThumbSublist()
	{
		return curThumbSublist;
	}

	public void setCurThumbSublist(List<Photo> curThumbSublist)
	{
		this.curThumbSublist = curThumbSublist;
		curListCounter++;
	}
	
	public String getCurrentThumbContainerId()
	{
		return "thumb_"+curListCounter;
	}

	public List<List<Photo>> getListOfThumbSubLists(){
		curListCounter= 0;
		List<List<Photo>> outputlist = new ArrayList<List<Photo>>();
		
		Set<Photo> set = this.getPage().getPhotos();
		List<Photo> list = new ArrayList<Photo>();
		for(Photo p: set){
			list.add(p);
			System.out.println(p.getUrl());
		}
		int counter = 0;
		boolean stop = false;
		while(!stop){
			outputlist.add(list.subList(counter,
Math.min(counter+maxListsize,outputlist.size())));
			if(list.size()<=counter+maxListsize){
				stop = true;
			}
			counter += maxListsize;
		}
		return outputlist;
	}

	public Photo getCurPhotoAsThumb()
	{
		return curPhotoAsThumb;
	}

	public void setCurPhotoAsThumb(Photo curPhotoAsThumb)
	{
		this.curPhotoAsThumb = curPhotoAsThumb;
	}
-- 
View this message in context: http://www.nabble.com/T5%3A-nested-loops-don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16330163.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: nested loops don't work (can't figure this one out)

Posted by Britske <gb...@gmail.com>.
Arghh. Thanks a lot! I missed that. I figured it couldn't be a Tapestry
thing. 

I traced back why I thought that the resulting sublist had an element (while
in fact it didn't): apparently a sublist is nothing but a wrapper around the
source-list (which I didn't know_, which is why burried in the debug
parameters the sublist still shows to have an element. Anyhow, 

Thanks again. 


Jonathan Barker wrote:
> 
> Subtle logic error.
> 
> outputlist.add(list.subList(counter,
> Math.min(counter+maxListsize,outputlist.size())));
> 
> Should be 
> 
> outputlist.add(list.subList(counter,
> Math.min(counter+maxListsize, list.size())));
> 
> Gotta love those!
> 
> 
>> -----Original Message-----
>> From: Britske [mailto:gbrits@gmail.com]
>> Sent: Thursday, March 27, 2008 2:25 PM
>> To: users@tapestry.apache.org
>> Subject: T5: nested loops don't work (can't figure this one out)
>> 
>> 
>> Hi,
>> 
>> I'm breaking my head on this one.
>> I have  2 nested loops where the value of the outer loop is used as the
>> source of the inner loop.
>> 
>> The problem is that getCurPhotoAsThumb() is never called (as noticed by
>> debugging) thus nothing is rendered.
>> I've made sure that getCurThumbSublist() has at least 1 element.
>> 
>> Anyone?
>> 
>> I've supplied the relative template and class-parts:
>> 
>> TEMPLATE>
>> ---------------------
>> <t:loop source="listOfThumbSubLists" value="curThumbSublist">
>>   <div id="${currentThumbContainerId}" class="thumbcontainer">
>>        <t:loop source="curThumbSublist" value="curPhotoAsThumb">
>>            ${curPhotoAsThumb.url}
>>       	</t:loop>
>>    </div>
>>  </t:loop>
>> 
>> 
>> CLASS>
>> ---------------
>> private int maxListsize = 6;
>> private List<Photo> curThumbSublist;
>> private Photo curPhotoAsThumb;
>> private int curListCounter = 0;
>> 
>> 	public List<Photo> getCurThumbSublist()
>> 	{
>> 		return curThumbSublist;
>> 	}
>> 
>> 	public void setCurThumbSublist(List<Photo> curThumbSublist)
>> 	{
>> 		this.curThumbSublist = curThumbSublist;
>> 		curListCounter++;
>> 	}
>> 
>> 	public String getCurrentThumbContainerId()
>> 	{
>> 		return "thumb_"+curListCounter;
>> 	}
>> 
>> 	public List<List<Photo>> getListOfThumbSubLists(){
>> 		curListCounter= 0;
>> 		List<List<Photo>> outputlist = new ArrayList<List<Photo>>();
>> 
>> 		Set<Photo> set = this.getPage().getPhotos();
>> 		List<Photo> list = new ArrayList<Photo>();
>> 		for(Photo p: set){
>> 			list.add(p);
>> 			System.out.println(p.getUrl());
>> 		}
>> 		int counter = 0;
>> 		boolean stop = false;
>> 		while(!stop){
>> 			outputlist.add(list.subList(counter,
>> Math.min(counter+maxListsize,outputlist.size())));
>> 			if(list.size()<=counter+maxListsize){
>> 				stop = true;
>> 			}
>> 			counter += maxListsize;
>> 		}
>> 		return outputlist;
>> 	}
>> 
>> 	public Photo getCurPhotoAsThumb()
>> 	{
>> 		return curPhotoAsThumb;
>> 	}
>> 
>> 	public void setCurPhotoAsThumb(Photo curPhotoAsThumb)
>> 	{
>> 		this.curPhotoAsThumb = curPhotoAsThumb;
>> 	}
>> --
>> View this message in context: http://www.nabble.com/T5%3A-nested-loops-
>> don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16330163.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-nested-loops-don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16347650.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: nested loops don't work (can't figure this one out)

Posted by Howard Lewis Ship <hl...@gmail.com>.
Great catch.  Simpler is always better.

On Thu, Mar 27, 2008 at 4:10 PM, Jonathan Barker
<jo...@gmail.com> wrote:
> Subtle logic error.
>
>
>  outputlist.add(list.subList(counter,
>  Math.min(counter+maxListsize,outputlist.size())));
>
>  Should be
>
>
>  outputlist.add(list.subList(counter,
>  Math.min(counter+maxListsize, list.size())));
>
>  Gotta love those!
>
>
>
>
>  > -----Original Message-----
>  > From: Britske [mailto:gbrits@gmail.com]
>  > Sent: Thursday, March 27, 2008 2:25 PM
>  > To: users@tapestry.apache.org
>  > Subject: T5: nested loops don't work (can't figure this one out)
>  >
>  >
>  > Hi,
>  >
>  > I'm breaking my head on this one.
>  > I have  2 nested loops where the value of the outer loop is used as the
>  > source of the inner loop.
>  >
>  > The problem is that getCurPhotoAsThumb() is never called (as noticed by
>  > debugging) thus nothing is rendered.
>  > I've made sure that getCurThumbSublist() has at least 1 element.
>  >
>  > Anyone?
>  >
>  > I've supplied the relative template and class-parts:
>  >
>  > TEMPLATE>
>  > ---------------------
>  > <t:loop source="listOfThumbSubLists" value="curThumbSublist">
>  >   <div id="${currentThumbContainerId}" class="thumbcontainer">
>  >        <t:loop source="curThumbSublist" value="curPhotoAsThumb">
>  >            ${curPhotoAsThumb.url}
>  >               </t:loop>
>  >    </div>
>  >  </t:loop>
>  >
>  >
>  > CLASS>
>  > ---------------
>  > private int maxListsize = 6;
>  > private List<Photo> curThumbSublist;
>  > private Photo curPhotoAsThumb;
>  > private int curListCounter = 0;
>  >
>  >       public List<Photo> getCurThumbSublist()
>  >       {
>  >               return curThumbSublist;
>  >       }
>  >
>  >       public void setCurThumbSublist(List<Photo> curThumbSublist)
>  >       {
>  >               this.curThumbSublist = curThumbSublist;
>  >               curListCounter++;
>  >       }
>  >
>  >       public String getCurrentThumbContainerId()
>  >       {
>  >               return "thumb_"+curListCounter;
>  >       }
>  >
>  >       public List<List<Photo>> getListOfThumbSubLists(){
>  >               curListCounter= 0;
>  >               List<List<Photo>> outputlist = new ArrayList<List<Photo>>();
>  >
>  >               Set<Photo> set = this.getPage().getPhotos();
>  >               List<Photo> list = new ArrayList<Photo>();
>  >               for(Photo p: set){
>  >                       list.add(p);
>  >                       System.out.println(p.getUrl());
>  >               }
>  >               int counter = 0;
>  >               boolean stop = false;
>  >               while(!stop){
>  >                       outputlist.add(list.subList(counter,
>  > Math.min(counter+maxListsize,outputlist.size())));
>  >                       if(list.size()<=counter+maxListsize){
>  >                               stop = true;
>  >                       }
>  >                       counter += maxListsize;
>  >               }
>  >               return outputlist;
>  >       }
>  >
>  >       public Photo getCurPhotoAsThumb()
>  >       {
>  >               return curPhotoAsThumb;
>  >       }
>  >
>  >       public void setCurPhotoAsThumb(Photo curPhotoAsThumb)
>  >       {
>  >               this.curPhotoAsThumb = curPhotoAsThumb;
>  >       }
>  > --
>  > View this message in context: http://www.nabble.com/T5%3A-nested-loops-
>  > don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16330163.html
>  > Sent from the Tapestry - User mailing list archive at Nabble.com.
>  >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  > For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: nested loops don't work (can't figure this one out)

Posted by Jonathan Barker <jo...@gmail.com>.
Subtle logic error.

outputlist.add(list.subList(counter,
Math.min(counter+maxListsize,outputlist.size())));

Should be 

outputlist.add(list.subList(counter,
Math.min(counter+maxListsize, list.size())));

Gotta love those!


> -----Original Message-----
> From: Britske [mailto:gbrits@gmail.com]
> Sent: Thursday, March 27, 2008 2:25 PM
> To: users@tapestry.apache.org
> Subject: T5: nested loops don't work (can't figure this one out)
> 
> 
> Hi,
> 
> I'm breaking my head on this one.
> I have  2 nested loops where the value of the outer loop is used as the
> source of the inner loop.
> 
> The problem is that getCurPhotoAsThumb() is never called (as noticed by
> debugging) thus nothing is rendered.
> I've made sure that getCurThumbSublist() has at least 1 element.
> 
> Anyone?
> 
> I've supplied the relative template and class-parts:
> 
> TEMPLATE>
> ---------------------
> <t:loop source="listOfThumbSubLists" value="curThumbSublist">
>   <div id="${currentThumbContainerId}" class="thumbcontainer">
>        <t:loop source="curThumbSublist" value="curPhotoAsThumb">
>            ${curPhotoAsThumb.url}
>       	</t:loop>
>    </div>
>  </t:loop>
> 
> 
> CLASS>
> ---------------
> private int maxListsize = 6;
> private List<Photo> curThumbSublist;
> private Photo curPhotoAsThumb;
> private int curListCounter = 0;
> 
> 	public List<Photo> getCurThumbSublist()
> 	{
> 		return curThumbSublist;
> 	}
> 
> 	public void setCurThumbSublist(List<Photo> curThumbSublist)
> 	{
> 		this.curThumbSublist = curThumbSublist;
> 		curListCounter++;
> 	}
> 
> 	public String getCurrentThumbContainerId()
> 	{
> 		return "thumb_"+curListCounter;
> 	}
> 
> 	public List<List<Photo>> getListOfThumbSubLists(){
> 		curListCounter= 0;
> 		List<List<Photo>> outputlist = new ArrayList<List<Photo>>();
> 
> 		Set<Photo> set = this.getPage().getPhotos();
> 		List<Photo> list = new ArrayList<Photo>();
> 		for(Photo p: set){
> 			list.add(p);
> 			System.out.println(p.getUrl());
> 		}
> 		int counter = 0;
> 		boolean stop = false;
> 		while(!stop){
> 			outputlist.add(list.subList(counter,
> Math.min(counter+maxListsize,outputlist.size())));
> 			if(list.size()<=counter+maxListsize){
> 				stop = true;
> 			}
> 			counter += maxListsize;
> 		}
> 		return outputlist;
> 	}
> 
> 	public Photo getCurPhotoAsThumb()
> 	{
> 		return curPhotoAsThumb;
> 	}
> 
> 	public void setCurPhotoAsThumb(Photo curPhotoAsThumb)
> 	{
> 		this.curPhotoAsThumb = curPhotoAsThumb;
> 	}
> --
> View this message in context: http://www.nabble.com/T5%3A-nested-loops-
> don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16330163.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: nested loops don't work (can't figure this one out)

Posted by Howard Lewis Ship <hl...@gmail.com>.
That should work just fine.  Nothing jumps out at me as being wrong.

In fact, I just tried a simplified test case and it worked fine:

 public Object[][] getData() {
        return new Object[][] {
                { "fred", "flintstone" },
                { "barney", "rubble" }
        };
    }

    @Property
    private Object[] column;

  <ul>
                    <t:loop source="data" value="column">
                        <li>
                            ROW:
                            <ul>
                                <t:loop source="column" value="var:temp">
                                    <li>${var:temp}</li>
                                </t:loop>
                            </ul>
                        </li>
                    </t:loop>
                </ul>

Which rendered as:

 <ul>

                        <li>
                            ROW:
                            <ul>

                                    <li>fred</li>

                                    <li>flintstone</li>

                            </ul>
                        </li>


                        <li>
                            ROW:
                            <ul>

                                    <li>barney</li>

                                    <li>rubble</li>

                            </ul>
                        </li>

                </ul>


On Thu, Mar 27, 2008 at 11:24 AM, Britske <gb...@gmail.com> wrote:
>
>  Hi,
>
>  I'm breaking my head on this one.
>  I have  2 nested loops where the value of the outer loop is used as the
>  source of the inner loop.
>
>  The problem is that getCurPhotoAsThumb() is never called (as noticed by
>  debugging) thus nothing is rendered.
>  I've made sure that getCurThumbSublist() has at least 1 element.
>
>  Anyone?
>
>  I've supplied the relative template and class-parts:
>
>  TEMPLATE>
>  ---------------------
>  <t:loop source="listOfThumbSubLists" value="curThumbSublist">
>   <div id="${currentThumbContainerId}" class="thumbcontainer">
>        <t:loop source="curThumbSublist" value="curPhotoAsThumb">
>            ${curPhotoAsThumb.url}
>         </t:loop>
>    </div>
>   </t:loop>
>
>
>  CLASS>
>  ---------------
>  private int maxListsize = 6;
>  private List<Photo> curThumbSublist;
>  private Photo curPhotoAsThumb;
>  private int curListCounter = 0;
>
>         public List<Photo> getCurThumbSublist()
>         {
>                 return curThumbSublist;
>         }
>
>         public void setCurThumbSublist(List<Photo> curThumbSublist)
>         {
>                 this.curThumbSublist = curThumbSublist;
>                 curListCounter++;
>         }
>
>         public String getCurrentThumbContainerId()
>         {
>                 return "thumb_"+curListCounter;
>         }
>
>         public List<List<Photo>> getListOfThumbSubLists(){
>                 curListCounter= 0;
>                 List<List<Photo>> outputlist = new ArrayList<List<Photo>>();
>
>                 Set<Photo> set = this.getPage().getPhotos();
>                 List<Photo> list = new ArrayList<Photo>();
>                 for(Photo p: set){
>                         list.add(p);
>                         System.out.println(p.getUrl());
>                 }
>                 int counter = 0;
>                 boolean stop = false;
>                 while(!stop){
>                         outputlist.add(list.subList(counter,
>  Math.min(counter+maxListsize,outputlist.size())));
>                         if(list.size()<=counter+maxListsize){
>                                 stop = true;
>                         }
>                         counter += maxListsize;
>                 }
>                 return outputlist;
>         }
>
>         public Photo getCurPhotoAsThumb()
>         {
>                 return curPhotoAsThumb;
>         }
>
>         public void setCurPhotoAsThumb(Photo curPhotoAsThumb)
>         {
>                 this.curPhotoAsThumb = curPhotoAsThumb;
>         }
>  --
>  View this message in context: http://www.nabble.com/T5%3A-nested-loops-don%27t-work-%28can%27t-figure-this-one-out%29-tp16330163p16330163.html
>  Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org