You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by freaquac <jo...@freaquac.de> on 2004/04/04 22:16:49 UTC
When to set a source for a foreach component to null?
Hi all,
a simple question with hopefully a simple anwser, but I haven't found it yet:
I have two pages. The first page maintains a set of Items stored in an
ArrayList. The second page should display the Items in a form and give the
possibility of feedback. The difficulty is that the ArrayList of Items should
be cleared as soon as they are displayed by page 2.
To avoid a stale page the best place to do so would possibly be in the forms
listener method on page2. But that wouldn't cover the "evil" browser back
button. The user can navigate back and the ArrayList is not deleted/cleared.
Another possibility is to delete the ArrayList shortly after calling page2
from page1 (listed beneath). But that gets me a get a stale page.
//in page 1
public void viewItems(IRequestCycle cycle){
ViewItems page2 = (ViewItems )cycle.getPage("ViewItems");
view.viewItems(cycle,(ArrayList)getUser().getItems());
getUser().setItems(null);
return;
}
As far as I understand the ListEdit component it wouldn't change anything if I
use it. Cause in the synchronize method of the ListEdit component I would
always get null values back because my source ArrayList is deleted and I
couldn't synchronize the keys against values.
The only doable possibility I see in the moment is to add a delete flag to the
Item class and set it as soon as it is displayed as part of the ArrayList.
Then I can check at page1 if there is something to delete from before calling
page2 the next time.
As I'm new to tapestry and not sure if I have already grasped the ways behind
it ;-), I would love to have some input from you about this problem. Maybe I
have overseen the obvious.
Greetings,
Markus
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: When to set a source for a foreach component to null?
Posted by John Studarus <st...@jhlconsulting.com>.
Let me get this straight...
Page 1 lists the items and Page 2 edits an item?
Let's call Page 1 ListItems and Page 2 EditItem.
You'll want something like:
ListItems:
public abstract Item getItem() ; // this is set in the foreach
// this is called from an actionlink
public void viewItems(IRequestCycle cycle){
EditItemPage next_page = (EditItemPage)cycle.getPage("EditItem");
next_page.setItem(cycle, getItem()) ; // or if you are using Hibernate set the Item Id/Key
cycle.activate(next_page) ;
return;
}
EditItem:
<property-specification name="item" type="Item" persistent="yes"/>
// this item will be reset automatically by Tapestry when sent back to the pool for reuse
public abstract Item setItem(Item item) ; // persistent object from page file
Does that make sense? Did I understand your problem correctly?
John
On Sun, Apr 04, 2004 at 10:16:49PM +0200, freaquac wrote:
> Hi all,
> a simple question with hopefully a simple anwser, but I haven't found it yet:
>
> I have two pages. The first page maintains a set of Items stored in an
> ArrayList. The second page should display the Items in a form and give the
> possibility of feedback. The difficulty is that the ArrayList of Items should
> be cleared as soon as they are displayed by page 2.
>
> To avoid a stale page the best place to do so would possibly be in the forms
> listener method on page2. But that wouldn't cover the "evil" browser back
> button. The user can navigate back and the ArrayList is not deleted/cleared.
>
> Another possibility is to delete the ArrayList shortly after calling page2
> from page1 (listed beneath). But that gets me a get a stale page.
>
> //in page 1
> public void viewItems(IRequestCycle cycle){
> ViewItems page2 = (ViewItems )cycle.getPage("ViewItems");
> view.viewItems(cycle,(ArrayList)getUser().getItems());
>
> getUser().setItems(null);
> return;
> }
>
>
> As far as I understand the ListEdit component it wouldn't change anything if I
> use it. Cause in the synchronize method of the ListEdit component I would
> always get null values back because my source ArrayList is deleted and I
> couldn't synchronize the keys against values.
>
> The only doable possibility I see in the moment is to add a delete flag to the
> Item class and set it as soon as it is displayed as part of the ArrayList.
> Then I can check at page1 if there is something to delete from before calling
> page2 the next time.
>
> As I'm new to tapestry and not sure if I have already grasped the ways behind
> it ;-), I would love to have some input from you about this problem. Maybe I
> have overseen the obvious.
>
> Greetings,
> Markus
>
>
> ---------------------------------------------------------------------
> 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