You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Wouter De Vaal <wo...@gmail.com> on 2005/09/09 16:32:13 UTC
foreach within block only called once
Hi,
I have a strange problem with a foreach component within a block that
only gets called once, but the block renders multiple times. This code
worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
because the foreach source doesn't get reevaluated I think.
Regards,
Wouter
PS: I've created a skeleton test page/class to test it:
html:
<html>
<body>
<comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
<comp jwcid="subMenuItems@Block">
Blah:<br/>
<comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
<comp jwcid="@Insert" value="ognl:menuName"/><br/>
<comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
<comp jwcid="@Insert" value="ognl:test"/>
<comp jwcid="@RenderBlock"
block="ognl:components.subMenuItems"/>
</comp>
</comp>
</comp>
</body>
</html>
Page file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<page-specification class="EditMenuItemTest">
</page-specification>
Java class:
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.html.BasePage;
public abstract class EditMenuItemTest extends BasePage implements
PageBeginRenderListener {
public class MenuItem {
private String name;
private List<MenuItem> subItems = new ArrayList<MenuItem>();
public MenuItem(String name) {
this.name = name;
}
public List<MenuItem> getSubItems() {
return subItems;
}
public void setSubItems(List<MenuItem> subItems) {
this.subItems = subItems;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
public void pageBeginRender(PageEvent evt) {
// create some menu items
MenuItem root = new MenuItem("root");
MenuItem a = new MenuItem("a");
MenuItem b = new MenuItem("b");
MenuItem c = new MenuItem("c");
MenuItem aa = new MenuItem("aa");
MenuItem ab = new MenuItem("ab");
MenuItem ac = new MenuItem("ac");
MenuItem aba = new MenuItem("aba");
MenuItem abb = new MenuItem("abb");
root.getSubItems().add(a);
root.getSubItems().add(b);
root.getSubItems().add(c);
c.getSubItems().add(aa);
c.getSubItems().add(ab);
c.getSubItems().add(ac);
ab.getSubItems().add(aba);
ab.getSubItems().add(abb);
setRootMenuItem(root);
}
public abstract MenuItem getRootMenuItem();
public abstract void setRootMenuItem(MenuItem root);
public abstract MenuItem getMenuItem();
public List<MenuItem> getMenuItems() {
if (getMenuItem() == null) {
System.out.println("get menu items with null called,
returning: " + getRootMenuItem().getSubItems());
return getRootMenuItem().getSubItems();
} else {
System.out.println("get menu items called, returning: " +
getMenuItem().getSubItems());
return getMenuItem().getSubItems();
}
}
public String getMenuName() {
System.out.println("get menu name called, current menu item: "
+ getMenuItem());
return getMenuItem().getName();
}
public String getTest() {
System.out.println("test called, current menu item: " + getMenuItem());
return "";
}
public boolean isHasAvailableSubItems() {
System.out.println("available:" + getMenuItem().getSubItems());
return (getMenuItem().getSubItems().size() > 0);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Wouter De Vaal <wo...@gmail.com>.
Ok, I'll take that approach then.
Just for the record. This used to work in tapestry 3.
Wouter
On 9/10/05, Ron Piterman <rp...@gmx.net> wrote:
> Hi,
> I looked at your code -
> it seems you try to render the same block recursivley. This will work
> only in really stateless components.
> I will assume the For component is not stateless - you can not
> recusivley render it from within the component itself because it will
> get "confused". Its similar to thread-saftyness - you can not use the
> same component from two threads, and you can not invoke the
> renderComponent method again from within the renderComponent.
>
> Instead, use a component which iterates through your tree from java and
> renders its body for each node.
>
> Cheers,
> Ron
>
>
>
>
>
> Wouter De Vaal:
> > I've tried the For component and it has the same behaviour.
> >
> > Anyone any idea's?
> >
> > Wouter
> >
> > On 9/9/05, Wouter De Vaal <wo...@gmail.com> wrote:
> >
> >>I'll try that.
> >>A remark though: the apidoc doesn't show anything about Foreach being
> >>deprecated.
> >>
> >>Wouter
> >>
> >>On 9/9/05, Ron Piterman <rp...@gmx.net> wrote:
> >>
> >>>Am not sure if it will solve your problem, but Foreach is deprecated.
> >>>Try using For instead, may be it will work...
> >>>
> >>>
> >>>
> >>> Wouter De Vaal:
> >>>
> >>>>Hi,
> >>>>
> >>>>I have a strange problem with a foreach component within a block that
> >>>>only gets called once, but the block renders multiple times. This code
> >>>>worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
> >>>>because the foreach source doesn't get reevaluated I think.
> >>>>
> >>>>Regards,
> >>>>Wouter
> >>>>
> >>>>PS: I've created a skeleton test page/class to test it:
> >>>>
> >>>>html:
> >>>><html>
> >>>><body>
> >>>> <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
> >>>> <comp jwcid="subMenuItems@Block">
> >>>> Blah:<br/>
> >>>> <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
> >>>> <comp jwcid="@Insert" value="ognl:menuName"/><br/>
> >>>> <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
> >>>> <comp jwcid="@Insert" value="ognl:test"/>
> >>>> <comp jwcid="@RenderBlock"
> >>>>block="ognl:components.subMenuItems"/>
> >>>> </comp>
> >>>> </comp>
> >>>> </comp>
> >>>></body>
> >>>></html>
> >>>>
> >>>>Page file:
> >>>><?xml version="1.0" encoding="UTF-8"?>
> >>>><!DOCTYPE page-specification PUBLIC
> >>>> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> >>>> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> >>>><page-specification class="EditMenuItemTest">
> >>>>
> >>>></page-specification>
> >>>>
> >>>>Java class:
> >>>>import java.util.ArrayList;
> >>>>import java.util.List;
> >>>>
> >>>>import org.apache.tapestry.event.PageBeginRenderListener;
> >>>>import org.apache.tapestry.event.PageEvent;
> >>>>import org.apache.tapestry.html.BasePage;
> >>>>
> >>>>public abstract class EditMenuItemTest extends BasePage implements
> >>>> PageBeginRenderListener {
> >>>>
> >>>> public class MenuItem {
> >>>>
> >>>> private String name;
> >>>> private List<MenuItem> subItems = new ArrayList<MenuItem>();
> >>>>
> >>>> public MenuItem(String name) {
> >>>> this.name = name;
> >>>> }
> >>>>
> >>>> public List<MenuItem> getSubItems() {
> >>>> return subItems;
> >>>> }
> >>>>
> >>>> public void setSubItems(List<MenuItem> subItems) {
> >>>> this.subItems = subItems;
> >>>> }
> >>>>
> >>>> public String getName() {
> >>>> return name;
> >>>> }
> >>>>
> >>>> @Override
> >>>> public String toString() {
> >>>> return name;
> >>>> }
> >>>>
> >>>> }
> >>>>
> >>>> public void pageBeginRender(PageEvent evt) {
> >>>> // create some menu items
> >>>> MenuItem root = new MenuItem("root");
> >>>> MenuItem a = new MenuItem("a");
> >>>> MenuItem b = new MenuItem("b");
> >>>> MenuItem c = new MenuItem("c");
> >>>> MenuItem aa = new MenuItem("aa");
> >>>> MenuItem ab = new MenuItem("ab");
> >>>> MenuItem ac = new MenuItem("ac");
> >>>> MenuItem aba = new MenuItem("aba");
> >>>> MenuItem abb = new MenuItem("abb");
> >>>> root.getSubItems().add(a);
> >>>> root.getSubItems().add(b);
> >>>> root.getSubItems().add(c);
> >>>> c.getSubItems().add(aa);
> >>>> c.getSubItems().add(ab);
> >>>> c.getSubItems().add(ac);
> >>>> ab.getSubItems().add(aba);
> >>>> ab.getSubItems().add(abb);
> >>>> setRootMenuItem(root);
> >>>> }
> >>>>
> >>>> public abstract MenuItem getRootMenuItem();
> >>>>
> >>>> public abstract void setRootMenuItem(MenuItem root);
> >>>>
> >>>> public abstract MenuItem getMenuItem();
> >>>>
> >>>> public List<MenuItem> getMenuItems() {
> >>>> if (getMenuItem() == null) {
> >>>> System.out.println("get menu items with null called,
> >>>>returning: " + getRootMenuItem().getSubItems());
> >>>> return getRootMenuItem().getSubItems();
> >>>> } else {
> >>>> System.out.println("get menu items called, returning: " +
> >>>>getMenuItem().getSubItems());
> >>>> return getMenuItem().getSubItems();
> >>>> }
> >>>> }
> >>>>
> >>>> public String getMenuName() {
> >>>> System.out.println("get menu name called, current menu item: "
> >>>> + getMenuItem());
> >>>> return getMenuItem().getName();
> >>>> }
> >>>>
> >>>> public String getTest() {
> >>>> System.out.println("test called, current menu item: " + getMenuItem());
> >>>> return "";
> >>>> }
> >>>>
> >>>> public boolean isHasAvailableSubItems() {
> >>>> System.out.println("available:" + getMenuItem().getSubItems());
> >>>> return (getMenuItem().getSubItems().size() > 0);
> >>>> }
> >>>>}
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>
> >>>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Ron Piterman <rp...@gmx.net>.
Hi,
I looked at your code -
it seems you try to render the same block recursivley. This will work
only in really stateless components.
I will assume the For component is not stateless - you can not
recusivley render it from within the component itself because it will
get "confused". Its similar to thread-saftyness - you can not use the
same component from two threads, and you can not invoke the
renderComponent method again from within the renderComponent.
Instead, use a component which iterates through your tree from java and
renders its body for each node.
Cheers,
Ron
Wouter De Vaal:
> I've tried the For component and it has the same behaviour.
>
> Anyone any idea's?
>
> Wouter
>
> On 9/9/05, Wouter De Vaal <wo...@gmail.com> wrote:
>
>>I'll try that.
>>A remark though: the apidoc doesn't show anything about Foreach being
>>deprecated.
>>
>>Wouter
>>
>>On 9/9/05, Ron Piterman <rp...@gmx.net> wrote:
>>
>>>Am not sure if it will solve your problem, but Foreach is deprecated.
>>>Try using For instead, may be it will work...
>>>
>>>
>>>
>>> Wouter De Vaal:
>>>
>>>>Hi,
>>>>
>>>>I have a strange problem with a foreach component within a block that
>>>>only gets called once, but the block renders multiple times. This code
>>>>worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
>>>>because the foreach source doesn't get reevaluated I think.
>>>>
>>>>Regards,
>>>>Wouter
>>>>
>>>>PS: I've created a skeleton test page/class to test it:
>>>>
>>>>html:
>>>><html>
>>>><body>
>>>> <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
>>>> <comp jwcid="subMenuItems@Block">
>>>> Blah:<br/>
>>>> <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
>>>> <comp jwcid="@Insert" value="ognl:menuName"/><br/>
>>>> <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
>>>> <comp jwcid="@Insert" value="ognl:test"/>
>>>> <comp jwcid="@RenderBlock"
>>>>block="ognl:components.subMenuItems"/>
>>>> </comp>
>>>> </comp>
>>>> </comp>
>>>></body>
>>>></html>
>>>>
>>>>Page file:
>>>><?xml version="1.0" encoding="UTF-8"?>
>>>><!DOCTYPE page-specification PUBLIC
>>>> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
>>>> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
>>>><page-specification class="EditMenuItemTest">
>>>>
>>>></page-specification>
>>>>
>>>>Java class:
>>>>import java.util.ArrayList;
>>>>import java.util.List;
>>>>
>>>>import org.apache.tapestry.event.PageBeginRenderListener;
>>>>import org.apache.tapestry.event.PageEvent;
>>>>import org.apache.tapestry.html.BasePage;
>>>>
>>>>public abstract class EditMenuItemTest extends BasePage implements
>>>> PageBeginRenderListener {
>>>>
>>>> public class MenuItem {
>>>>
>>>> private String name;
>>>> private List<MenuItem> subItems = new ArrayList<MenuItem>();
>>>>
>>>> public MenuItem(String name) {
>>>> this.name = name;
>>>> }
>>>>
>>>> public List<MenuItem> getSubItems() {
>>>> return subItems;
>>>> }
>>>>
>>>> public void setSubItems(List<MenuItem> subItems) {
>>>> this.subItems = subItems;
>>>> }
>>>>
>>>> public String getName() {
>>>> return name;
>>>> }
>>>>
>>>> @Override
>>>> public String toString() {
>>>> return name;
>>>> }
>>>>
>>>> }
>>>>
>>>> public void pageBeginRender(PageEvent evt) {
>>>> // create some menu items
>>>> MenuItem root = new MenuItem("root");
>>>> MenuItem a = new MenuItem("a");
>>>> MenuItem b = new MenuItem("b");
>>>> MenuItem c = new MenuItem("c");
>>>> MenuItem aa = new MenuItem("aa");
>>>> MenuItem ab = new MenuItem("ab");
>>>> MenuItem ac = new MenuItem("ac");
>>>> MenuItem aba = new MenuItem("aba");
>>>> MenuItem abb = new MenuItem("abb");
>>>> root.getSubItems().add(a);
>>>> root.getSubItems().add(b);
>>>> root.getSubItems().add(c);
>>>> c.getSubItems().add(aa);
>>>> c.getSubItems().add(ab);
>>>> c.getSubItems().add(ac);
>>>> ab.getSubItems().add(aba);
>>>> ab.getSubItems().add(abb);
>>>> setRootMenuItem(root);
>>>> }
>>>>
>>>> public abstract MenuItem getRootMenuItem();
>>>>
>>>> public abstract void setRootMenuItem(MenuItem root);
>>>>
>>>> public abstract MenuItem getMenuItem();
>>>>
>>>> public List<MenuItem> getMenuItems() {
>>>> if (getMenuItem() == null) {
>>>> System.out.println("get menu items with null called,
>>>>returning: " + getRootMenuItem().getSubItems());
>>>> return getRootMenuItem().getSubItems();
>>>> } else {
>>>> System.out.println("get menu items called, returning: " +
>>>>getMenuItem().getSubItems());
>>>> return getMenuItem().getSubItems();
>>>> }
>>>> }
>>>>
>>>> public String getMenuName() {
>>>> System.out.println("get menu name called, current menu item: "
>>>> + getMenuItem());
>>>> return getMenuItem().getName();
>>>> }
>>>>
>>>> public String getTest() {
>>>> System.out.println("test called, current menu item: " + getMenuItem());
>>>> return "";
>>>> }
>>>>
>>>> public boolean isHasAvailableSubItems() {
>>>> System.out.println("available:" + getMenuItem().getSubItems());
>>>> return (getMenuItem().getSubItems().size() > 0);
>>>> }
>>>>}
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Wouter De Vaal <wo...@gmail.com>.
I've tried the For component and it has the same behaviour.
Anyone any idea's?
Wouter
On 9/9/05, Wouter De Vaal <wo...@gmail.com> wrote:
> I'll try that.
> A remark though: the apidoc doesn't show anything about Foreach being
> deprecated.
>
> Wouter
>
> On 9/9/05, Ron Piterman <rp...@gmx.net> wrote:
> > Am not sure if it will solve your problem, but Foreach is deprecated.
> > Try using For instead, may be it will work...
> >
> >
> >
> > Wouter De Vaal:
> > > Hi,
> > >
> > > I have a strange problem with a foreach component within a block that
> > > only gets called once, but the block renders multiple times. This code
> > > worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
> > > because the foreach source doesn't get reevaluated I think.
> > >
> > > Regards,
> > > Wouter
> > >
> > > PS: I've created a skeleton test page/class to test it:
> > >
> > > html:
> > > <html>
> > > <body>
> > > <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
> > > <comp jwcid="subMenuItems@Block">
> > > Blah:<br/>
> > > <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
> > > <comp jwcid="@Insert" value="ognl:menuName"/><br/>
> > > <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
> > > <comp jwcid="@Insert" value="ognl:test"/>
> > > <comp jwcid="@RenderBlock"
> > > block="ognl:components.subMenuItems"/>
> > > </comp>
> > > </comp>
> > > </comp>
> > > </body>
> > > </html>
> > >
> > > Page file:
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <!DOCTYPE page-specification PUBLIC
> > > "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> > > "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> > > <page-specification class="EditMenuItemTest">
> > >
> > > </page-specification>
> > >
> > > Java class:
> > > import java.util.ArrayList;
> > > import java.util.List;
> > >
> > > import org.apache.tapestry.event.PageBeginRenderListener;
> > > import org.apache.tapestry.event.PageEvent;
> > > import org.apache.tapestry.html.BasePage;
> > >
> > > public abstract class EditMenuItemTest extends BasePage implements
> > > PageBeginRenderListener {
> > >
> > > public class MenuItem {
> > >
> > > private String name;
> > > private List<MenuItem> subItems = new ArrayList<MenuItem>();
> > >
> > > public MenuItem(String name) {
> > > this.name = name;
> > > }
> > >
> > > public List<MenuItem> getSubItems() {
> > > return subItems;
> > > }
> > >
> > > public void setSubItems(List<MenuItem> subItems) {
> > > this.subItems = subItems;
> > > }
> > >
> > > public String getName() {
> > > return name;
> > > }
> > >
> > > @Override
> > > public String toString() {
> > > return name;
> > > }
> > >
> > > }
> > >
> > > public void pageBeginRender(PageEvent evt) {
> > > // create some menu items
> > > MenuItem root = new MenuItem("root");
> > > MenuItem a = new MenuItem("a");
> > > MenuItem b = new MenuItem("b");
> > > MenuItem c = new MenuItem("c");
> > > MenuItem aa = new MenuItem("aa");
> > > MenuItem ab = new MenuItem("ab");
> > > MenuItem ac = new MenuItem("ac");
> > > MenuItem aba = new MenuItem("aba");
> > > MenuItem abb = new MenuItem("abb");
> > > root.getSubItems().add(a);
> > > root.getSubItems().add(b);
> > > root.getSubItems().add(c);
> > > c.getSubItems().add(aa);
> > > c.getSubItems().add(ab);
> > > c.getSubItems().add(ac);
> > > ab.getSubItems().add(aba);
> > > ab.getSubItems().add(abb);
> > > setRootMenuItem(root);
> > > }
> > >
> > > public abstract MenuItem getRootMenuItem();
> > >
> > > public abstract void setRootMenuItem(MenuItem root);
> > >
> > > public abstract MenuItem getMenuItem();
> > >
> > > public List<MenuItem> getMenuItems() {
> > > if (getMenuItem() == null) {
> > > System.out.println("get menu items with null called,
> > > returning: " + getRootMenuItem().getSubItems());
> > > return getRootMenuItem().getSubItems();
> > > } else {
> > > System.out.println("get menu items called, returning: " +
> > > getMenuItem().getSubItems());
> > > return getMenuItem().getSubItems();
> > > }
> > > }
> > >
> > > public String getMenuName() {
> > > System.out.println("get menu name called, current menu item: "
> > > + getMenuItem());
> > > return getMenuItem().getName();
> > > }
> > >
> > > public String getTest() {
> > > System.out.println("test called, current menu item: " + getMenuItem());
> > > return "";
> > > }
> > >
> > > public boolean isHasAvailableSubItems() {
> > > System.out.println("available:" + getMenuItem().getSubItems());
> > > return (getMenuItem().getSubItems().size() > 0);
> > > }
> > > }
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Wouter De Vaal <wo...@gmail.com>.
I'll try that.
A remark though: the apidoc doesn't show anything about Foreach being
deprecated.
Wouter
On 9/9/05, Ron Piterman <rp...@gmx.net> wrote:
> Am not sure if it will solve your problem, but Foreach is deprecated.
> Try using For instead, may be it will work...
>
>
>
> Wouter De Vaal:
> > Hi,
> >
> > I have a strange problem with a foreach component within a block that
> > only gets called once, but the block renders multiple times. This code
> > worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
> > because the foreach source doesn't get reevaluated I think.
> >
> > Regards,
> > Wouter
> >
> > PS: I've created a skeleton test page/class to test it:
> >
> > html:
> > <html>
> > <body>
> > <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
> > <comp jwcid="subMenuItems@Block">
> > Blah:<br/>
> > <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
> > <comp jwcid="@Insert" value="ognl:menuName"/><br/>
> > <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
> > <comp jwcid="@Insert" value="ognl:test"/>
> > <comp jwcid="@RenderBlock"
> > block="ognl:components.subMenuItems"/>
> > </comp>
> > </comp>
> > </comp>
> > </body>
> > </html>
> >
> > Page file:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE page-specification PUBLIC
> > "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> > "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> > <page-specification class="EditMenuItemTest">
> >
> > </page-specification>
> >
> > Java class:
> > import java.util.ArrayList;
> > import java.util.List;
> >
> > import org.apache.tapestry.event.PageBeginRenderListener;
> > import org.apache.tapestry.event.PageEvent;
> > import org.apache.tapestry.html.BasePage;
> >
> > public abstract class EditMenuItemTest extends BasePage implements
> > PageBeginRenderListener {
> >
> > public class MenuItem {
> >
> > private String name;
> > private List<MenuItem> subItems = new ArrayList<MenuItem>();
> >
> > public MenuItem(String name) {
> > this.name = name;
> > }
> >
> > public List<MenuItem> getSubItems() {
> > return subItems;
> > }
> >
> > public void setSubItems(List<MenuItem> subItems) {
> > this.subItems = subItems;
> > }
> >
> > public String getName() {
> > return name;
> > }
> >
> > @Override
> > public String toString() {
> > return name;
> > }
> >
> > }
> >
> > public void pageBeginRender(PageEvent evt) {
> > // create some menu items
> > MenuItem root = new MenuItem("root");
> > MenuItem a = new MenuItem("a");
> > MenuItem b = new MenuItem("b");
> > MenuItem c = new MenuItem("c");
> > MenuItem aa = new MenuItem("aa");
> > MenuItem ab = new MenuItem("ab");
> > MenuItem ac = new MenuItem("ac");
> > MenuItem aba = new MenuItem("aba");
> > MenuItem abb = new MenuItem("abb");
> > root.getSubItems().add(a);
> > root.getSubItems().add(b);
> > root.getSubItems().add(c);
> > c.getSubItems().add(aa);
> > c.getSubItems().add(ab);
> > c.getSubItems().add(ac);
> > ab.getSubItems().add(aba);
> > ab.getSubItems().add(abb);
> > setRootMenuItem(root);
> > }
> >
> > public abstract MenuItem getRootMenuItem();
> >
> > public abstract void setRootMenuItem(MenuItem root);
> >
> > public abstract MenuItem getMenuItem();
> >
> > public List<MenuItem> getMenuItems() {
> > if (getMenuItem() == null) {
> > System.out.println("get menu items with null called,
> > returning: " + getRootMenuItem().getSubItems());
> > return getRootMenuItem().getSubItems();
> > } else {
> > System.out.println("get menu items called, returning: " +
> > getMenuItem().getSubItems());
> > return getMenuItem().getSubItems();
> > }
> > }
> >
> > public String getMenuName() {
> > System.out.println("get menu name called, current menu item: "
> > + getMenuItem());
> > return getMenuItem().getName();
> > }
> >
> > public String getTest() {
> > System.out.println("test called, current menu item: " + getMenuItem());
> > return "";
> > }
> >
> > public boolean isHasAvailableSubItems() {
> > System.out.println("available:" + getMenuItem().getSubItems());
> > return (getMenuItem().getSubItems().size() > 0);
> > }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Ron Piterman <rp...@gmx.net>.
Am not sure if it will solve your problem, but Foreach is deprecated.
Try using For instead, may be it will work...
Wouter De Vaal:
> Hi,
>
> I have a strange problem with a foreach component within a block that
> only gets called once, but the block renders multiple times. This code
> worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
> because the foreach source doesn't get reevaluated I think.
>
> Regards,
> Wouter
>
> PS: I've created a skeleton test page/class to test it:
>
> html:
> <html>
> <body>
> <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
> <comp jwcid="subMenuItems@Block">
> Blah:<br/>
> <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
> <comp jwcid="@Insert" value="ognl:menuName"/><br/>
> <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
> <comp jwcid="@Insert" value="ognl:test"/>
> <comp jwcid="@RenderBlock"
> block="ognl:components.subMenuItems"/>
> </comp>
> </comp>
> </comp>
> </body>
> </html>
>
> Page file:
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> <page-specification class="EditMenuItemTest">
>
> </page-specification>
>
> Java class:
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.tapestry.event.PageBeginRenderListener;
> import org.apache.tapestry.event.PageEvent;
> import org.apache.tapestry.html.BasePage;
>
> public abstract class EditMenuItemTest extends BasePage implements
> PageBeginRenderListener {
>
> public class MenuItem {
>
> private String name;
> private List<MenuItem> subItems = new ArrayList<MenuItem>();
>
> public MenuItem(String name) {
> this.name = name;
> }
>
> public List<MenuItem> getSubItems() {
> return subItems;
> }
>
> public void setSubItems(List<MenuItem> subItems) {
> this.subItems = subItems;
> }
>
> public String getName() {
> return name;
> }
>
> @Override
> public String toString() {
> return name;
> }
>
> }
>
> public void pageBeginRender(PageEvent evt) {
> // create some menu items
> MenuItem root = new MenuItem("root");
> MenuItem a = new MenuItem("a");
> MenuItem b = new MenuItem("b");
> MenuItem c = new MenuItem("c");
> MenuItem aa = new MenuItem("aa");
> MenuItem ab = new MenuItem("ab");
> MenuItem ac = new MenuItem("ac");
> MenuItem aba = new MenuItem("aba");
> MenuItem abb = new MenuItem("abb");
> root.getSubItems().add(a);
> root.getSubItems().add(b);
> root.getSubItems().add(c);
> c.getSubItems().add(aa);
> c.getSubItems().add(ab);
> c.getSubItems().add(ac);
> ab.getSubItems().add(aba);
> ab.getSubItems().add(abb);
> setRootMenuItem(root);
> }
>
> public abstract MenuItem getRootMenuItem();
>
> public abstract void setRootMenuItem(MenuItem root);
>
> public abstract MenuItem getMenuItem();
>
> public List<MenuItem> getMenuItems() {
> if (getMenuItem() == null) {
> System.out.println("get menu items with null called,
> returning: " + getRootMenuItem().getSubItems());
> return getRootMenuItem().getSubItems();
> } else {
> System.out.println("get menu items called, returning: " +
> getMenuItem().getSubItems());
> return getMenuItem().getSubItems();
> }
> }
>
> public String getMenuName() {
> System.out.println("get menu name called, current menu item: "
> + getMenuItem());
> return getMenuItem().getName();
> }
>
> public String getTest() {
> System.out.println("test called, current menu item: " + getMenuItem());
> return "";
> }
>
> public boolean isHasAvailableSubItems() {
> System.out.println("available:" + getMenuItem().getSubItems());
> return (getMenuItem().getSubItems().size() > 0);
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: foreach within block only called once
Posted by Mind Bridge <mi...@yahoo.com>.
Hi,
Just wanted to mention that appropriate modifications have been made to
SVN HEAD and the problem has been resolved. The provided code should
work okay in the next beta, both with Foreach and For.
-mb
Wouter De Vaal wrote:
>Hi,
>
>I have a strange problem with a foreach component within a block that
>only gets called once, but the block renders multiple times. This code
>worked in tapestry 3, but gives an overflow in tapestry 4 beta 6,
>because the foreach source doesn't get reevaluated I think.
>
>Regards,
>Wouter
>
>PS: I've created a skeleton test page/class to test it:
>
>html:
><html>
><body>
> <comp jwcid="@RenderBlock" block="ognl:components.subMenuItems"/>
> <comp jwcid="subMenuItems@Block">
> Blah:<br/>
> <comp jwcid="@Foreach" source="ognl:menuItems" value="ognl:menuItem">
> <comp jwcid="@Insert" value="ognl:menuName"/><br/>
> <comp jwcid="@Conditional" condition="ognl:hasAvailableSubItems">
> <comp jwcid="@Insert" value="ognl:test"/>
> <comp jwcid="@RenderBlock"
>block="ognl:components.subMenuItems"/>
> </comp>
> </comp>
> </comp>
></body>
></html>
>
>Page file:
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
><page-specification class="EditMenuItemTest">
>
></page-specification>
>
>Java class:
>import java.util.ArrayList;
>import java.util.List;
>
>import org.apache.tapestry.event.PageBeginRenderListener;
>import org.apache.tapestry.event.PageEvent;
>import org.apache.tapestry.html.BasePage;
>
>public abstract class EditMenuItemTest extends BasePage implements
> PageBeginRenderListener {
>
> public class MenuItem {
>
> private String name;
> private List<MenuItem> subItems = new ArrayList<MenuItem>();
>
> public MenuItem(String name) {
> this.name = name;
> }
>
> public List<MenuItem> getSubItems() {
> return subItems;
> }
>
> public void setSubItems(List<MenuItem> subItems) {
> this.subItems = subItems;
> }
>
> public String getName() {
> return name;
> }
>
> @Override
> public String toString() {
> return name;
> }
>
> }
>
> public void pageBeginRender(PageEvent evt) {
> // create some menu items
> MenuItem root = new MenuItem("root");
> MenuItem a = new MenuItem("a");
> MenuItem b = new MenuItem("b");
> MenuItem c = new MenuItem("c");
> MenuItem aa = new MenuItem("aa");
> MenuItem ab = new MenuItem("ab");
> MenuItem ac = new MenuItem("ac");
> MenuItem aba = new MenuItem("aba");
> MenuItem abb = new MenuItem("abb");
> root.getSubItems().add(a);
> root.getSubItems().add(b);
> root.getSubItems().add(c);
> c.getSubItems().add(aa);
> c.getSubItems().add(ab);
> c.getSubItems().add(ac);
> ab.getSubItems().add(aba);
> ab.getSubItems().add(abb);
> setRootMenuItem(root);
> }
>
> public abstract MenuItem getRootMenuItem();
>
> public abstract void setRootMenuItem(MenuItem root);
>
> public abstract MenuItem getMenuItem();
>
> public List<MenuItem> getMenuItems() {
> if (getMenuItem() == null) {
> System.out.println("get menu items with null called,
>returning: " + getRootMenuItem().getSubItems());
> return getRootMenuItem().getSubItems();
> } else {
> System.out.println("get menu items called, returning: " +
>getMenuItem().getSubItems());
> return getMenuItem().getSubItems();
> }
> }
>
> public String getMenuName() {
> System.out.println("get menu name called, current menu item: "
> + getMenuItem());
> return getMenuItem().getName();
> }
>
> public String getTest() {
> System.out.println("test called, current menu item: " + getMenuItem());
> return "";
> }
>
> public boolean isHasAvailableSubItems() {
> System.out.println("available:" + getMenuItem().getSubItems());
> return (getMenuItem().getSubItems().size() > 0);
> }
>}
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org