Title: RE: [Tapestry-developer] request for help with rewind

Thanks very much Tom, the beginResponse thing was exactly
what I needed. I'll have to go through and remove misguided
references to the attach method.

Howard, the developer's guide talks a fair bit about attaching
and detaching pages, and says the attach method gets called
whenever a page is pulled from a pool. That's why I thought
the attach method was the right hook for me, but of course
it's too early in the request cycle.

I can't find any mention of the beginResponse in the Developer's
Guide or the Tutorial. (Many thanks for the single-page version
that made these searches possible!)

As an aside, I've got a number of simple tapestry projects that
demonstrate how to do various things in tapestry. These are
designed to demonstrate a single feature in isolation from
everything else, kind of like Tom's set of files that he
sent in response to my email. I'd be happy to share them
if there is interest, but I don't know who/where/what format
to submit them in.

-----Original Message-----
From: Tom Davies [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 10, 2002 12:48 PM
To: Tapestry Developer (E-mail)
Subject: Re: [Tapestry-developer] request for help with rewind


Phil,

Here's some code which does what (I think) you want.

Please tell me if it doesn't...

Tom

Howard,

There is one thing which puzzled me while I was writing it -- why did I
need to create a session (by creating a persistent page property) before
the Action component would work?

TestPage.java
------------------------------------------------------------------
import com.primix.tapestry.BasePage;
import com.primix.tapestry.IEngine;
import com.primix.tapestry.IRequestCycle;
import com.primix.tapestry.IResponseWriter;

public class TestPage extends BasePage
{
        public static class Thing
        {
          public Thing(String name)
          {
            this.name = name;
            state = false;
          }
       
          private String name;
          private boolean state;

     public void setName(String name)
     {
       this.name = name;
     }

     public void setState(boolean state)
     {
       this.state = state;
     }

     public boolean getState()
     {
       return state;
     }

     public String getName()
     {
       return name;
     }
        }
       
    static Thing[] s_database = new Thing[] {new Thing("Thing One"), new
Thing("Thing Two"), new Thing("Thing Three")};
    private Thing thing;
    private Thing[] database;

   public void setThing(Thing thing)
   {
     this.thing = thing;
   }

   public Thing getThing()
   {
     return thing;
   }

   public Thing[] getThings()
   {
     return database;
   }

   public void setThings(Thing[] things)
   {
     database = things;
   }

   public void toggle(IRequestCycle cycle)
   {
     getThing().setState(!getThing().getState());
     // update database here
   }

   public void beginResponse(IResponseWriter writer, IRequestCycle cycle)
   {
     // read database here
     database = s_database;
     fireObservedChange("things", database);
   }
}

TestPage.jwc
---------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE specification PUBLIC
   "-//Howard Ship//Tapestry Specification 1.1//EN"
   "http://tapestry.sf.net/dtd/Tapestry_1_1.dtd">

<specification class="TestPage">
        <component id="for" type="Foreach">
                <binding name="source" property-path="page.things"/>
                <binding name="value" property-path="page.thing"/>
        </component>
        <component id="name" type="Insert">
        <binding name="value" property-path="thing.name"/>
        </component>
        <component id="state" type="Insert">
        <binding name="value" property-path="thing.state"/>
        </component>
        <component id="toggle" type="Action">
        <binding name="listener" property-path="listeners.toggle"/>
        <static-binding name="stateful">Boolean.FALSE</static-binding>
        </component>
</specification>

TestPage.html
--------------------------------------------------------------------
<span jwcid="for">
        <a href=""#"" jwcid="toggle"><span jwcid="name">Item
Name</span></a>&nbsp;<span jwcid="state"/><br>
</span>


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer

Reply via email to