Hi DH,

it would be:

-----------------------------------------------------------------------
<table t:type="grid" t:source="userSource" row="currentUser" 
add="location_city">
   <t:parameter name="location_citycell">
        ${currentUser.location.city}
   </t:parameter>
</table>
-----------------------------------------------------------------------

(Note the "add" instead of include - you want to add something not already 
existing, not include something.)

On your page you have to define

-----------------------------------------------------------------------
@Parameter
User userSource;
-----------------------------------------------------------------------

to keep track of the current grid object.
So much for the first method.


If you want to have to have a Location always represented as a String 
containing its city toString():

-----------------------------------------------------------------------
class Location {
        // [...]
        public String toString() {
                return city;
        }
}
-----------------------------------------------------------------------

Now you have to define a Translator for Tapestry (I use a template for all 
classes which implement toString()):

-----------------------------------------------------------------------
public class ModelTranslator<ModelClass> implements Translator<ModelClass> {

           public Class<ModelClass> getType() {
               return null;
           }

           public ModelClass parseClient(String arg0, Messages arg1)
                   throws ValidationException {
               throw new ValidationException("ModelTranslator cannot implement 
parseClient()");
           }

           public String toClient(ModelClass arg0) {
               return arg0.toString();
           }

}
-----------------------------------------------------------------------

Now you only have to announce your Translator in to your AppModule.java:

-----------------------------------------------------------------------
   @SuppressWarnings("unchecked")
   public static void contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class, 
String> configuration) {
        configuration.add(User.class, "user");
   }

   @SuppressWarnings("unchecked") {
        configuration.add("user", new ModelTranslator<User>());
} -----------------------------------------------------------------------

...and after doing this, you have to do exactly *nothing* to add it to your 
grid - it will do so per default. :)

Tobias


dhning schrieb:

Hi, Tobias

Thanks for reply.

I am newbie of customizing grid component.
I guess what you mean like this?:
<table t:type="grid" t:source="userSource" include="location_city">
    <t:parameter name="location_cityheader">
    </t:parameter>
    <t:parameter name="location_citycell">
    </t:parameter>
</table>

But exception message still exists: "Bean editor model for User does not contain a 
property named 'location_city'".

Thanks!

DH


----- Original Message ----- From: "Tobias Wehrum" <[EMAIL PROTECTED]>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Friday, April 18, 2008 4:20 PM
Subject: Re: T5: Is there a simple way to display property of embedded instance 
in Grid?


Hi DH,

you can teach Location a standard way to be outputted by overwriting the toString() function of Location.

Now you can output the String returned by toString() simply by including "location".

If you want to output different properties of Location and not in one cell, I think you will have to add location_city, location_street etc and implement <t:parameter> blocks for it.

Hope that helps,
Tobias

dhning schrieb:
Hi, All

Case: A user own a location while the location is comprised of city, street...
public class User {
  private Location location;
  // setter & getter
}
public class Location {
  private String city;
 // setter & getter
}

In the user list page, I want to display the city as one column in Grid.
But it doesn't work like this <table t:type="grid" t:source="userSource" 
include="location.city"></table>.
The exception message is "User does not contain a property named 
'location.city'".

Is there a simple way to implement such function?

Thanks in advance.
DH
---------------------------------------------------------------------
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