Jabbar,

I actually implemented your test code yesterday with all of my changes,
so I can verify at least it works for me.  FYI, I'm using the release
version of Tapestry 4.0 and Hivemind 1.1.

I didn't mention Home.java also needs to implement SelectablePage, so
that might be an issue.  But if you are not seeing perSelectedPage as a
property of Page1, 2, and 3, please verify that SelectablePage is
implemented by each of them.  You could also convert SelectablePage to a
class which extends BasePage, and then Home, Page1, 2, and 3 could
simply extend SelectablePage.  You could of course eliminate
SelectablePage completely if you prefer to duplicate the property
persistence code in each one.

I believe everything else from your original code is fine.  If you add a
page to your selection list which does not persist the perSelectedPage
property, the target page should be rendered correctly but the list
value will return to the default (Home).

Even though this method worked for me, I noticed that for each page
render I have one hidden form value (encapsulating the perSelectedPage
property) for each page.  The parameters are named "appstate:Home",
"appstate:Page1", etc.  So, every page in your application will have
these additional parameters encoded.  It really would be best if the
property could be bound to the Border component, but as I stepped
through the code I could see that the containing page is being inspected
for persistent properties rather than the component itself.

Another option which works well is session persistence (using a Visit or
Global property), but this may not be an option if you are trying to
remain stateless.

Shawn

Quoting Jabbar <[EMAIL PROTECTED]>:

> Hello Shawn,
> 
> Thank you for your reply. I've tried your suggestion but it doesn't
> work.
> 
> Inside the method 'public void selectedPage(IRequestCycle cycle) '
> 'PropertyUtils.isWritable(cycle.getPage(), "perSelectedPage") '
> always
> returns false
> 
> and inside the method  'public void pageBeginRender(PageEvent event)
> {'
> '
>
PropertyUtils.isReadable(event.getRequestCycle().getPage(),"perSelectedPage")
> )'
> 
> always returns false.
> 
> I have used java.util.List
> PropertyUtils.getReadableProperties(java.lang.Object target)
> and
> 
> java.util.List PropertyUtils.getWriteableProperties(java.lang.Object
> target)
> 
> both do not return 'perSelectedPage'
> 
> Do you have any more ideas?
> 
> 
> On 23/01/06, Shawn Church <[EMAIL PROTECTED]> wrote:
> > Jabbar,
> >
> > Since persistent properties follow the page containing each
> component
> > (rather than the component itself), I believe you are going to have
> to
> > have the "perSelectedPage" property bound to each "selectable" page
> itself.
> >
> > There may be more elegant ways to accomplish what you are wanting,
> but
> > I've included some code below which might help.
> >
> > Please try this (or something similar):
> >
> > Border.java:
> >
> > public abstract class Border extends BaseComponent implements
> > PageBeginRenderListener
> > {
> >   public abstract String getSelectedPage();
> >
> >   public abstract void setSelectedPage(String page);
> >
> >   public void selectedPage(IRequestCycle cycle) {
> >      cycle.activate(getSelectedPage());
> >
> >      if( PropertyUtils.isWritable(cycle.getPage(),
> "perSelectedPage") )
> >         PropertyUtils.write(cycle.getPage(), "perSelectedPage",
> > getSelectedPage());
> >   }
> >
> >   public PageSelectionModel getPageSelectionModel() {
> >      return new PageSelectionModel();
> >   }
> >
> >   public void pageBeginRender(PageEvent event) {
> >      if( !event.getRequestCycle().isRewinding() )
> >      {
> >         if(
> PropertyUtils.isReadable(event.getRequestCycle().getPage(),
> > "perSelectedPage") )
> >         {
> >            String selpage = ( String )
> > PropertyUtils.read(event.getRequestCycle().getPage(),
> "perSelectedPage");
> >            if( selpage != null )
> >               setSelectedPage(( String ) selpage);
> >         }
> >      }
> >   }
> > }
> >
> > One each for Page1.page, Page2.page, Page3.page, etc.:
> >
> > <?xml version="1.0"?>
> > <!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="com.technolog.page.Page1">
> > </page-specification>
> >
> > One each for Page1.java, Page2.java, Page3.java, etc.:
> >
> > public abstract class Page1 extends BasePage implements
> SelectablePage
> > {
> > }
> >
> > SelectablePage.java:
> >
> > import org.apache.tapestry.IPage;
> > import org.apache.tapestry.annotations.Persist;
> >
> > public interface SelectablePage extends IPage
> > {
> >   @Persist("client:app")
> >   public abstract String getPerSelectedPage();
> >
> >   public abstract void setPerSelectedPage(String page);
> > }
> >
> > Shawn
> >
> >
> > Quoting Jabbar <[EMAIL PROTECTED]>:
> >
> > > Hello all,
> > > I'm having serious client side persistence problems. I have a
> border
> > > component which has a property selection component. From there I
> can
> > > select which page I want to goto, by default the home page is
> shown.
> > >
> > > If I select a new page then the property selection does not show
> the
> > > new page, but the main body of the page shows the selected page.
> > >
> > > Obviously there is something I don't understand regarding client
> > > side
> > > persistence.
> > > I have included the source for a test web application I wrote.
> Does
> > > any body have any suggestions?
> > >
> > > --
> > > Thanks
> > >
> > > Jabbar Azam
> > >
> > > //-- start of source code
> > >
> >
>
---------------------------------------------------------------------------------------------------
> > >
> > > Border.java
> > > ----------------
> > > package com.technolog.page;
> > >
> > > import org.apache.tapestry.BaseComponent;
> > > import org.apache.tapestry.IRequestCycle;
> > > import org.apache.tapestry.annotations.Persist;
> > > import org.apache.tapestry.event.PageBeginRenderListener;
> > > import org.apache.tapestry.event.PageEvent;
> > >
> > > import com.technolog.model.PageSelectionModel;
> > >
> > > /**
> > >  * This the parent component of all the other web pages.  Every
> web
> > > page is placed
> > >  * within this page.  This allows the header, footer and
> navigation
> > > to
> > > be modified
> > >  * without changing every page.
> > >  *
> > >  * @author Jabbar Azam
> > >  *
> > >  */
> > > public abstract class Border extends BaseComponent implements
> > > PageBeginRenderListener{
> > >
> > >     @Persist("client:app")
> > >     public abstract String getPerSelectedPage();
> > >     public abstract void setPerSelectedPage(String page);
> > >
> > >     public abstract String getSelectedPage();
> > >     public abstract void setSelectedPage(String page);
> > >
> > >     public void selectedPage(IRequestCycle cycle) {
> > >         setPerSelectedPage(getSelectedPage());
> > >         cycle.activate(getSelectedPage());
> > >     }
> > >
> > >     public PageSelectionModel getPageSelectionModel() {
> > >
> > >         return new PageSelectionModel();
> > >     }
> > >
> > >     public void pageBeginRender(PageEvent event) {
> > >         if (!event.getRequestCycle().isRewinding()) {
> > >             setSelectedPage(getPerSelectedPage());
> > >         }
> > >     }
> > >
> > > }
> > >
> > >
> >
>
---------------------------------------------------------------------------------------
> > > PageSelectionModel.java
> > > ------------------------------------
> > >
> > > package com.technolog.model;
> > >
> > > import java.io.Serializable;
> > > import java.util.List;
> > > import java.util.Vector;
> > >
> > > import org.apache.tapestry.form.IPropertySelectionModel;
> > >
> > >
> > > public class PageSelectionModel implements
> IPropertySelectionModel,
> > > Serializable {
> > >
> > >     /**
> > >      *
> > >      */
> > >     private static final long serialVersionUID =
> > > 5195300859295677036L;
> > >     protected List<String> pageList = new Vector<String>();
> > >
> > >     /**
> > >      *
> > >      * @param siteListDAO
> > >      * @param user
> > >      */
> > >     public PageSelectionModel() {
> > >
> > >       pageList.add("Home");
> > >       pageList.add("Page1");
> > >       pageList.add("Page2");
> > >       pageList.add("Page3");
> > >
> > >
> > >     }
> > >     /**
> > >      *
> > >      */
> > >     public int getOptionCount() {
> > >         return pageList.size();
> > >     }
> > >     /**
> > >      *
> > >      */
> > >     public Object getOption(int idx) {
> > >         return pageList.get(idx);
> > >     }
> > >
> > >     /**
> > >      *
> > >      */
> > >     public String getValue(int idx) {
> > >         return Integer.toString(idx);
> > >     }
> > >
> > >     /**
> > >      *
> > >      */
> > >     public Object translateValue(String idx) {
> > >         return getOption(Integer.parseInt(idx));
> > >     }
> > >
> > >     public String getLabel(int idx) {
> > >         return (String)getOption(idx);
> > >     }
> > >
> > > }
> > >
> > >
> > >
> >
>
--------------------------------------------------------------------------------------------------------
> > >
> > > Border.html
> > > -----------------
> > > <html>
> > > <head jwcid="@Shell" title="test">
> > > <title>Test</title>
> > > </head>
> > >
> > > <body jwcid="@Body">
> > >
> > >   <table>
> > >   <form jwcid="@Form"
> listener="listener:selectedPage"><tr><td><span
> > > jwcid="pageSelection"/></td></tr></form>
> > >   <tr><td><span jwcid="@RenderBody"/></td></tr>
> > >
> > >   </table>
> > >
> > > </body>
> > > </html>
> > >
> > >
> >
>
--------------------------------------------------------------------------------------------------------------
> > >
> > > Border.jwc
> > > ---------------
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <!DOCTYPE component-specification
> > >       PUBLIC "-//Apache Software Foundation//Tapestry
> Specification
> > > 4.0//EN"
> > >       "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>
> > > <!-- generated by Spindle, http://spindle.sourceforge.net -->
> > >
> > > <component-specification class="com.technolog.page.Border"
> > > allow-informal-parameters="no">
> > >
> > >       <component id="pageSelection" type="PropertySelection">
> > >               <binding name="model" value="pageSelectionModel"/>
> > >               <binding name="value" value="selectedPage"/>
> > >               <binding name="submitOnChange"
> value="literal:yes"/>
> > >       </component>
> > > </component-specification>
> > >
> > >
> >
>
-------------------------------------------------------------------------------------------------------------
> > >
> > > Home.html
> > > ----------------
> > > <span jwcid="$content$">
> > > <span jwcid="@Border">
> > > <h1>Home Page</h1>
> > > </span>
> > > </span>
> > >
> >
>
--------------------------------------------------------------------------------------------------------------
> > >
> > > Page1.html
> > > -----------------
> > > <span jwcid="$content$">
> > > <span jwcid="@Border">
> > > <h1>Page 1</h1>
> > > </span>
> > > </span>
> > >
> > >
> >
>
-------------------------------------------------------------------------------------------------------------
> > >
> > > Page 2.html
> > > ------------------
> > > <span jwcid="$content$">
> > > <span jwcid="@Border">
> > > <h1>Page 2</h1>
> > > </span>
> > > </span>
> > >
> > >
> >
>
-------------------------------------------------------------------------------------------------------------
> > >
> > > Page3.html
> > > -----------------
> > > <span jwcid="$content$">
> > > <span jwcid="@Border">
> > > <h1>Page 3</h1>
> > > </span>
> > > </span>
> > >
> > > //end of source code
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > >
> > >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail:
> [EMAIL PROTECTED]
> >
> >
> 
> 
> --
> Thanks
> 
> Jabbar Azam
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to