You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Francois Malet <fr...@yahoo.fr> on 2009/07/01 13:39:01 UTC

Grid / sortable additionnal column

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

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, Jul 1, 2009 at 8:39 AM, Francois Malet<fr...@yahoo.fr> 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@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Grid / sortable additionnal column

Posted by Claude Dubois <cd...@gmail.com>.
Hello,

I am trying to add a sortable column like you, but when I try to implement
PropertyConduit, as you explained, it doesn't work, and I have a
java.lang.NullPointerException.

Could you explain how you implement your class, and what problems you got
(if you got someones).

Thank you


Francois Malet wrote:
> 
> 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);
>     }
> 
> 
> }
> 

-- 
View this message in context: http://old.nabble.com/Grid---sortable-additionnal-column-tp24288365p28386255.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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