You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2006/02/14 11:24:30 UTC

Re: Need a quick DataSqueezer teachin

I have introduced my own test squeezer, to try and get the hang of it. But
so far I'm not getting it.

The squeezer is working, I've introduced it in hivemodule.xml, and it runs
(I see the logging) when I load my page.

It creates hidden values in html with texts like this:
"VCmy.package.MyClass:110",
the class name and the unique id, from my base class.

When I submit the form, the unsqueeze method returns instances of
my.package.MyClass, with its "id" property set to the correct value. But in
my form listener, the collection containing these objects is empty.

Any clues?

On 1/12/06, Alan Chandler <al...@chandlerfamily.org.uk> wrote:
>
> On Wednesday 11 January 2006 19:47, Alan Chandler wrote:
> > I am wanting to take a friendly URL of the form /MyApp/view/somestring
> ...
> >
> > But that has failed - saying there is no strategy for unsqueezing
> strings.
> > So I am now stuck
> >
> > Where do I go next????????
>
>
> Cracked it.  I realised after looking at the DataSqeezerUtil class that I
> needed to register a new StringAdaptor with the DataSqueezerImpl
>
> All is working perfectly now:-)
> --
> Alan Chandler
> http://www.chandlerfamily.org.uk
> Open Source. It's the difference between trust and antitrust.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: Need a quick DataSqueezer teachin

Posted by Inge Solvoll <in...@gmail.com>.
Tried a lot of stuff now, browsing the wiki for answers here:
http://wiki.apache.org/jakarta-tapestry/DataSqueezer

As I said, the squeeze adaptor I created kicks in, the squeeze() and
unsqueeze() methods logs on rewind and render, and the correct hidden values
are created in html. But my page properties remain untouched when I reach
the form listener. The values of the text fields are not populated into page
properties. The items collection is an empty collection when the form
listener is reached.

Here are extracts of my code, any input would be appreciated!

My HTML file:

<body jwcid="@Body">

<form jwcid="@Form" listener="listener:formListener">
  <span jwcid="@Hidden" value="ognl:activeId"/>

  Active id is:
  <span jwcid="@Insert" value="ognl:activeId">666</span>
  <br><br>

    <span jwcid="@For" source="ognl:items" value="ognl:currentItem">
      <span jwcid="@Insert" value="ognl:currentItem.name"/><br>
       <input type="text" jwcid="@TextField" value="ognl:currentItem.name"/>
       <br>
    </span>

    <br><br>

      <input type="button" jwcid="@Submit" value="Submit form now"/>
</form>
</body>

.page file:

<page-specification class="Test">

    <description>Page for prototyping new code</description>

    <property name="items"/>
    <property name="activeId"/>
    <property name="currentItem"/>

</page-specification>


My class files here:

public abstract class Test extends BasePage implements
PageBeginRenderListener {

  static Log log = LogFactory.getLog(Test.class);

  public abstract Collection getItems();
  public abstract void setItems(Collection c);

  public void pageBeginRender(PageEvent event) {

    if (!getRequestCycle().isRewinding()) {
      initItems();
    }
    else {
      if (getItems() == null) {
        setItems(new Vector());
      }
    }
  }

  public void formListener(IRequestCycle cycle) {
    Collection items = getItems();
    for (Iterator iter = items.iterator(); iter.hasNext();) {
      Item currItem = (Item) iter.next();
      log.debug("Current item id: " + currItem.getId() + ", name: " +
currItem.getName());
    }
  }

  private void initItems() {
    Collection items = new Vector();

    items.add(new Item(new Long(1), "Item 1"));
    items.add(new Item(new Long(2), "Item 2"));

    setItems(items);
  }
}


public class IdAdaptor implements SqueezeAdaptor {

  static Log log = LogFactory.getLog(IdAdaptor.class);

  private final static String PREFIX = "C";

  public String getPrefix() {
    return PREFIX;
  }

  public Class getDataClass() {
    return Item.class;
  }

  public String squeeze(DataSqueezer squeezer, Object data) {
    log.debug("squeeze: " + data);
    String name = data.getClass().getName();
    Item i = (Item) data;
    return PREFIX + name + ":" + i.getId();
  }

  public Object unsqueeze(DataSqueezer squeezer, String string) {
    log.debug("unsqueeze: " + string);
    // Strip the prefix
    string = string.substring(1);

    String[] strings = string.split(":");

    try {
      Long id = new Long(strings[1]);
      Class c = Class.forName(strings[0]);
      Object item = (Object) c.newInstance();
      ((Item) item).setId(id);
      log.debug("Returning Item object: " + item);
      return item;
    }
    catch (Throwable t) {
      log.error(t);
    }

    return null;
  }

}


hivemodule.xml:

    <service-point id="IdAdaptor" interface="
org.apache.tapestry.util.io.SqueezeAdaptor">
     <invoke-factory>
       <construct class="common.tapestry.IdAdaptor">
       </construct>
     </invoke-factory>
   </service-point>

  <contribution configuration-id="tapestry.data.SqueezeAdaptors">
    <adaptor object="service:IdAdaptor"/>
  </contribution>



Inge

On 2/14/06, Inge Solvoll <in...@gmail.com> wrote:
>
> I have introduced my own test squeezer, to try and get the hang of it. But
> so far I'm not getting it.
>
> The squeezer is working, I've introduced it in hivemodule.xml, and it runs
> (I see the logging) when I load my page.
>
> It creates hidden values in html with texts like this: "
> VCmy.package.MyClass:110", the class name and the unique id, from my base
> class.
>
> When I submit the form, the unsqueeze method returns instances of
> my.package.MyClass, with its "id" property set to the correct value. But
> in my form listener, the collection containing these objects is empty.
>
> Any clues?
>
> On 1/12/06, Alan Chandler <al...@chandlerfamily.org.uk> wrote:
> >
> > On Wednesday 11 January 2006 19:47, Alan Chandler wrote:
> > > I am wanting to take a friendly URL of the form /MyApp/view/somestring
> > ...
> > >
> > > But that has failed - saying there is no strategy for unsqueezing
> > strings.
> > > So I am now stuck
> > >
> > > Where do I go next????????
> >
> >
> > Cracked it.  I realised after looking at the DataSqeezerUtil class that
> > I
> > needed to register a new StringAdaptor with the DataSqueezerImpl
> >
> > All is working perfectly now:-)
> > --
> > Alan Chandler
> > http://www.chandlerfamily.org.uk
> > Open Source. It's the difference between trust and antitrust.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>