Hi There,
I'm happy to say I'm slowly coming to grips with the Tapestry way of thinking, though 
I'm at a stage where I'm struggling with trying to make a component stateful.

The question is really: How do I persist a search result so that the user can scroll 
through it.

Given I have a component called VisualSearch. This is a visual component that has an 
text box for the keywords and submit button. When I click 'Go' I do the search and the 
resulting itemList is a property of this component. 
ie
================
public class VisualSearch extends BaseComponent {

    private String keywords;
    private List   itemList;

    // no code for brevity
    public String getKeywords() { .. }
    public void setKeywords(String s) { .. }
    public List getItemList() {..}
    public void setItemList(List l) {...}
    public  void formSubmit(IRequestCycle cycle){
        // do search and set itemList
    }
======================

That's all good and well. I then have another visual component that displays an 
itemList, ie it does a foreach loop and formats output in nice html. This will most 
likely be placed on a different page.
======================
public class SearchResult extends BaseComponent {    private List itemList;
    private Item item;
    private int currPageNumber; // current page of scrollset user is looking at.
    private int maxPageNumber;  // Maximum page number
    private int itemsPerPage;    // # of items per page. (determines above two params)

// All  getter/setter methods here.

}
==========================================

What's the best way to do this?
Is it by making the component persistent or is using the Visit object the only way? 
ie, by putting the itemList intot he visit object? 
I get the feeling that's what I need to do but I would be extremely thankful if people 
could describe how to get components persisting components like this, or instead tell 
me I'm way off the garden path.. :-/

Hope this makes a bit of sense. 
Thanks for reading my post.

Regards,
Patrick.

ps. Anyone have a persistent component they could possibly share with the forum? It 
would help a lot of newbies.
Sorry for my clerical error.
 
In component java code, fireObservedChange() is invoked if recorderLocked is *NOT* true, otherwise this mothod is not invoked.
 
When I click the page for the first time, an exception that indicates some states were not been persistented is thrown.
 
What's wrong with my code?
 
----- Original Message -----
Sent: Friday, September 20, 2002 7:02 PM
Subject: Re: [Tapestry-developer] component state

I think you are missing the point.  Why are you trying to change a persistent property while rendering your page?  You need to *not* do that.
----- Original Message -----
From: xuzhou
Sent: Friday, September 20, 2002 1:46 AM
Subject: Re: [Tapestry-developer] component state

 public void pageBeginRender(PageEvent event){
  recorderLocked = true;
 }
 public void pageEndRender(PageEvent event){
  recorderLocked = false;
 }
 
The above is render listener's mothod. The listener is added to the page in finishLoad(). In component java code, fireObservedChange() is invoked if recorderLocked is true, otherwise this mothod is not invoked.
 
When I click the page for the first time, an exception that indicates some states were not been persistented is thrown.
 
What's wrong with my code?
 
----- Original Message -----
Sent: Friday, September 20, 2002 11:16 AM
Subject: Re: [Tapestry-developer] component state

Page recorders are locked after the page begins rendering a real response.  You must ensure that no changes occur to persistent properties after this point.  Use the PageRenderListener events to know when a render is about to start.
----- Original Message -----
From: xuzhou
Sent: Thursday, September 19, 2002 10:30 PM
Subject: Re: [Tapestry-developer] component state

net.sf.tapestry.ApplicationRuntimeException
    Page recorder for page Home is locked after a commit(), but received a change to property separator of component Home/datagrid.
Stack Trace:
  • net.sf.tapestry.record.PageRecorder.observeChange(PageRecorder.java:144)
  • net.sf.tapestry.AbstractComponent.fireObservedChange(AbstractComponent.java:283)
The above is throwned exception when the fireObservedChange() is invoked to persistent the component's state. How to avoid this exception?
 
----- Original Message -----
Sent: Thursday, September 12, 2002 7:32 PM
Subject: Re: [Tapestry-developer] component state

A component can invoke fireObservedChange() just like a page can.
 
However, components don't have the equivalent of detach().
 
Instead, they must implement interface PageDetachListener and implement method finishLoad() to register as a listener with the page.
----- Original Message -----
From: xuzhou
Sent: Thursday, September 12, 2002 3:48 AM
Subject: [Tapestry-developer] component state

Hi there,
 
How to develope a component which can persistent its state by itself?
 
I have refer the Persistent Component State in Chapter 5 of Developer's Guide, but the component seems to lost its state.
 
How to do?
 
Thanks.
 
 

Reply via email to