Re: @BeanForm for a Cat and its Owner (PropertySelection)

2007-01-20 Thread munich
Thanks!

But this is the answer I feared :-(

Do you think it would be possible to make the BeanForm component more 
intelligent, that it will do that automatically?

It would only need to call the getName() method on referenced objects

This way you would save lots of code and even for the most complex object 
a single BeanForm line would do the trick..

I played a round with the cognition framework and I think it was already doing 
something similiar as far as I remember:

http://dev.thelabllc.com/cognition/



 Original-Nachricht 
Datum: Sat, 20 Jan 2007 01:40:11 +0100
Von: DJ Gredler [EMAIL PROTECTED]
An: Tapestry users users@tapestry.apache.org
Betreff: Re: @BeanForm for a Cat and its Owner (PropertySelection)

 You will need to create a small class that implements
 IPropertySelectionModel (maybe inside your page class):
 
 private final static class OwnerPropertySelectionModel implements
 IPropertySelectionModel {
 private ListOwner owners;
 public OwnerPropertySelectionModel( ListOwner owners ) {
 this.owners = owners;
 }
 public int getOptionCount() {
 return this.owners.size();
 }
 public Object getOption( int index ) {
 return this.owners.get( index );
 }
 public String getLabel( int index ) {
 Owner owner = this.owners.get( index );
 return ( owner != null ? owner.getName() : null );
 }
 public String getValue( int index ) {
 return String.valueOf( index );
 }
 public Object translateValue( String value ) {
 if( value == null ) return null;
 else return this.owners.get( Integer.valueOf( value ) );
 }
 }
 
 You will then need to return an instance of this class from a method on
 your
 page:
 
 public IPropertySelectionModel getOwnerPSM() {
 ListOwner owners = ...
 return new OwnerPropertySelectionModel( owners );
 }
 
 Then just add another binding to your BeanForm component:
 
owner_model=ognl:ownerPSM
 
 All of this code was taken from the example webapp, specifically the
 binding
 override examples page. Check it out if you get a chance.
 
 Take care,
 
 Daniel
 
 
 On 1/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
  I got it working now...I saw some helpful additional comments on the
  sourceforge page. I used the annotations now and did without a page
 file.
  I also added a library line to the application file. Another error was
  that I forgot the PageBeginRender interface so that the object was null
 when
  the page loaded as the method to create an empty object was not called.
 
  But another questionI am trying to edit a an object that depends on
  another object/table which i would like to solve as a
  PropertySelection...preferrably without doing a PropertySelectionModel
 class
  for it.
 
 
  E.g.:
 
  Table with Cats
  ~~~
 
  (mapped to Cat.java)
 
  id  name   owner_id
  1   Felix2
  2   Garfield 1
 
 
  Table with Owners
  ~~
 
  (mapped to Owner.java)
 
  id  name
  1   Sally
  2   Peter
 
  So if I want to edit or create a new Cat I want the Owner to be
 selectable
  as PropertySelection.
 
  span jwcid=@bf:BeanForm bean=ognl:cat save=listener:save
  delete=listener:delete/
 
  Just displays a text field for the owner_id
 
 
  has anyone got a good example how to do it? Or does it end up gettings a
  bit messy with lots of coding for a PropertySelectionModel class?
 
  Thanks!
 
   Original-Nachricht 
  Datum: Fri, 19 Jan 2007 00:52:55 +0100
  Von: DJ Gredler [EMAIL PROTECTED]
  An: Tapestry users users@tapestry.apache.org
  Betreff: Re: @BeanForm How do you use it ???
 
   Hi,
  
   What version are you using? Can you post the full stack trace? I
 looked
  at
   the source code and I don't really see how line 149 of BeanForm.java
 can
   cause a NPE...
  
   Also, what library id are you using in the .application file? Those
   jwcid's
   should probably include the library id, no?
  
   Take care,
  
   Daniel
  
  
   On 1/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   
I have tried:
   
span jwcid=@BeanForm bean=ognl:foo properties=ognl:'name'
save=listener:onSave /
   
as well as:
   
span jwcid=@BeanForm bean=ognl:foo beanProperties=ognl:'name'
save=listener:onSave /
   
but it comes up with:
   
ognl.OgnlException
beanProperties
   
java.lang.NullPointerException
Stack Trace:
   
*
   com.domain.components.BeanForm.getBeanProperties(BeanForm.java:149)
   
Any pointing in the right direction?
   
Thanks!
   
   
 -
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
   
   
 
  -
  To unsubscribe

@BeanForm for a Cat and its Owner (PropertySelection)

2007-01-19 Thread munich
I got it working now...I saw some helpful additional comments on the 
sourceforge page. I used the annotations now and did without a page file.
I also added a library line to the application file. Another error was that I 
forgot the PageBeginRender interface so that the object was null when the page 
loaded as the method to create an empty object was not called.

But another questionI am trying to edit a an object that depends on another 
object/table which i would like to solve as a PropertySelection...preferrably 
without doing a PropertySelectionModel class for it.


E.g.:

Table with Cats
~~~

(mapped to Cat.java)

id  name   owner_id
1   Felix2
2   Garfield 1


Table with Owners
~~

(mapped to Owner.java)

id  name
1   Sally
2   Peter

So if I want to edit or create a new Cat I want the Owner to be selectable as 
PropertySelection.

span jwcid=@bf:BeanForm bean=ognl:cat save=listener:save 
delete=listener:delete/

Just displays a text field for the owner_id


has anyone got a good example how to do it? Or does it end up gettings a bit 
messy with lots of coding for a PropertySelectionModel class?

Thanks!

 Original-Nachricht 
Datum: Fri, 19 Jan 2007 00:52:55 +0100
Von: DJ Gredler [EMAIL PROTECTED]
An: Tapestry users users@tapestry.apache.org
Betreff: Re: @BeanForm How do you use it ???

 Hi,
 
 What version are you using? Can you post the full stack trace? I looked at
 the source code and I don't really see how line 149 of BeanForm.java can
 cause a NPE...
 
 Also, what library id are you using in the .application file? Those
 jwcid's
 should probably include the library id, no?
 
 Take care,
 
 Daniel
 
 
 On 1/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
  I have tried:
 
  span jwcid=@BeanForm bean=ognl:foo properties=ognl:'name'
  save=listener:onSave /
 
  as well as:
 
  span jwcid=@BeanForm bean=ognl:foo beanProperties=ognl:'name'
  save=listener:onSave /
 
  but it comes up with:
 
  ognl.OgnlException
  beanProperties
 
  java.lang.NullPointerException
  Stack Trace:
 
  *
 com.domain.components.BeanForm.getBeanProperties(BeanForm.java:149)
 
  Any pointing in the right direction?
 
  Thanks!
 
  -
  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]



Re: @BeanForm for a Cat and its Owner (PropertySelection)

2007-01-19 Thread DJ Gredler

You will need to create a small class that implements
IPropertySelectionModel (maybe inside your page class):

   private final static class OwnerPropertySelectionModel implements
IPropertySelectionModel {
   private ListOwner owners;
   public OwnerPropertySelectionModel( ListOwner owners ) {
   this.owners = owners;
   }
   public int getOptionCount() {
   return this.owners.size();
   }
   public Object getOption( int index ) {
   return this.owners.get( index );
   }
   public String getLabel( int index ) {
   Owner owner = this.owners.get( index );
   return ( owner != null ? owner.getName() : null );
   }
   public String getValue( int index ) {
   return String.valueOf( index );
   }
   public Object translateValue( String value ) {
   if( value == null ) return null;
   else return this.owners.get( Integer.valueOf( value ) );
   }
   }

You will then need to return an instance of this class from a method on your
page:

   public IPropertySelectionModel getOwnerPSM() {
   ListOwner owners = ...
   return new OwnerPropertySelectionModel( owners );
   }

Then just add another binding to your BeanForm component:

  owner_model=ognl:ownerPSM

All of this code was taken from the example webapp, specifically the binding
override examples page. Check it out if you get a chance.

Take care,

Daniel


On 1/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


I got it working now...I saw some helpful additional comments on the
sourceforge page. I used the annotations now and did without a page file.
I also added a library line to the application file. Another error was
that I forgot the PageBeginRender interface so that the object was null when
the page loaded as the method to create an empty object was not called.

But another questionI am trying to edit a an object that depends on
another object/table which i would like to solve as a
PropertySelection...preferrably without doing a PropertySelectionModel class
for it.


E.g.:

Table with Cats
~~~

(mapped to Cat.java)

id  name   owner_id
1   Felix2
2   Garfield 1


Table with Owners
~~

(mapped to Owner.java)

id  name
1   Sally
2   Peter

So if I want to edit or create a new Cat I want the Owner to be selectable
as PropertySelection.

span jwcid=@bf:BeanForm bean=ognl:cat save=listener:save
delete=listener:delete/

Just displays a text field for the owner_id


has anyone got a good example how to do it? Or does it end up gettings a
bit messy with lots of coding for a PropertySelectionModel class?

Thanks!

 Original-Nachricht 
Datum: Fri, 19 Jan 2007 00:52:55 +0100
Von: DJ Gredler [EMAIL PROTECTED]
An: Tapestry users users@tapestry.apache.org
Betreff: Re: @BeanForm How do you use it ???

 Hi,

 What version are you using? Can you post the full stack trace? I looked
at
 the source code and I don't really see how line 149 of BeanForm.java can
 cause a NPE...

 Also, what library id are you using in the .application file? Those
 jwcid's
 should probably include the library id, no?

 Take care,

 Daniel


 On 1/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
  I have tried:
 
  span jwcid=@BeanForm bean=ognl:foo properties=ognl:'name'
  save=listener:onSave /
 
  as well as:
 
  span jwcid=@BeanForm bean=ognl:foo beanProperties=ognl:'name'
  save=listener:onSave /
 
  but it comes up with:
 
  ognl.OgnlException
  beanProperties
 
  java.lang.NullPointerException
  Stack Trace:
 
  *
 com.domain.components.BeanForm.getBeanProperties(BeanForm.java:149)
 
  Any pointing in the right direction?
 
  Thanks!
 
  -
  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]