Grid / sortable additionnal column

View: New views
3 Messages — Rating Filter:   Alert me  

Grid / sortable additionnal column

by Francois Malet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I use Tapestry 5.1.0.5
My goal is to add a column to a grid and to make it sortable.
Of course, this column is not part of the grid datasource (otherwise I wouldn't need to add it).
I have written a page based on example provided here:
http://wiki.apache.org/tapestry/Tapestry5GridComponent
Everything seems to be ok (up and down arrows are displaid), but when I try to sort on this additionnal column, I get a nullpointer exception. (but when I try to sort on other columns it still works).

So, I guess I've done something unporperly, but I don't manage to find what. Do u have any idea?

Here is the error :
java.lang.NullPointerException
org.apache.tapestry5.internal.grid.CollectionGridDataSource$2.compare(CollectionGridDataSource.java:78)
org.apache.tapestry5.internal.grid.CollectionGridDataSource$3.compare(CollectionGridDataSource.java:91)
java.util.Arrays.mergeSort(Arrays.java:1284)

Here is my class page :

public class UploadsIndex {

    @Inject
    private UploadManager uploadManager;
    /** The model. */
    @Retain
    private BeanModel beanModel;

    /** The bean model source. */
    @Inject
    private BeanModelSource beanModelSource;

    /** The resources. */
    @Inject
    private Messages messages;

    void pageLoaded() {
           beanModel=beanModelSource.createEditModel(Upload.class, messages);           
           PropertyModel dModel= beanModel.add("download",null);
           dModel.sortable(true);
           
    }
    
    public BeanModel getBeanModel() {    
        return beanModel;
    }
    
    public List<Upload> getAllUploads() {      
        return uploadManager.findAll();
    }

     @Property
    private Upload upload;    
    
}

And here is the tml page :
...
    <body>
        <h1>All Uploads</h1>
        <t:grid t:id="grid" t:source="allUploads" row="upload" exclude="uploadId" t:model="beanModel" >        
        <t:parameter name="downloadCell">             
                   <t:actionlink t:id="downloadUpload" context="upload.uploadId">${upload.name}</t:actionlink>
        </t:parameter>        
        </t:grid>             
    </body>
...

Thanks For your help!
Kind Regards
Emmanuel



Re: Grid / sortable additionnal column

by Thiago H. de Paula Figueiredo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 1, 2009 at 8:39 AM, Francois Malet<francois_malet@...> wrote:
> Hello,

Hi!

>            PropertyModel dModel= beanModel.add("download",null);

The problem is here: Grid doesn't know how to get the download
property (column) value to sort it, as you passed a null
PropertyConduit to the add() method.
You need to implement a PropertyConduit for and pass it to the add()
method. If Upload implements sortable, you don't need to
dModel.sortable(true);.

Here's one example for a PropertyConduit related to the manager
property (which is of type User) of the Project class:

public class ProjectManagerPropertyConduit implements PropertyConduit {

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
                return null;
        }

        /**
         * @see org.apache.tapestry5.PropertyConduit#get(java.lang.Object)
         */
        public Object get(Object instance) {
                Project project = (Project) instance;
                return project.getManager();
        }

        @SuppressWarnings("unchecked")
        public Class getPropertyType() {
                return User.class;
        }

        public void set(Object instance, Object value) {

                Project project = (Project) instance;
                project.setManager((User) value);

        }

}


--
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Parent Message unknown Re: Grid / sortable additionnal column

by Francois Malet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perfect!
Here is my PropertyConduit implementation

public class DownloadPropertyConduit implements PropertyConduit {

    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        return null;
    }

    /**
     * @see org.apache.tapestry5.PropertyConduit#get(java.lang.Object)
     */
    public Object get(Object instance) {
        Upload upload = (Upload) instance;
        return upload.getName();
    }

    @SuppressWarnings("unchecked")
    public Class getPropertyType() {
        return String.class;
    }

    public void set(Object instance, Object value) {
        Upload upload = (Upload) instance;
        upload.setName((String) value);
    }


}

--- En date de : Mer 1.7.09, Thiago H. de Paula Figueiredo <thiagohp@...> a écrit :

De: Thiago H. de Paula Figueiredo <thiagohp@...>
Objet: Re: Grid / sortable additionnal column
À: "Tapestry users" <users@...>
Date: Mercredi 1 Juillet 2009, 12h46

On Wed, Jul 1, 2009 at 8:39 AM, Francois Malet<francois_malet@...> wrote:
> Hello,

Hi!

>            PropertyModel dModel= beanModel.add("download",null);

The problem is here: Grid doesn't know how to get the download
property (column) value to sort it, as you passed a null
PropertyConduit to the add() method.
You need to implement a PropertyConduit for and pass it to the add()
method. If Upload implements sortable, you don't need to
dModel.sortable(true);.

Here's one example for a PropertyConduit related to the manager
property (which is of type User) of the Project class:

public class ProjectManagerPropertyConduit implements PropertyConduit {

    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        return null;
    }

    /**
     * @see org.apache.tapestry5.PropertyConduit#get(java.lang.Object)
     */
    public Object get(Object instance) {
        Project project = (Project) instance;
        return project.getManager();
    }

    @SuppressWarnings("unchecked")
    public Class getPropertyType() {
        return User.class;
    }

    public void set(Object instance, Object value) {

        Project project = (Project) instance;
        project.setManager((User) value);

    }

}


--
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...