You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Scot Mcphee <sc...@gmail.com> on 2009/08/10 07:41:25 UTC

Using a checkbox in a grid component

Hello

Does any one have a short recipe how to use a checkbox in a grid  
component?

What I need to do is fairly simple - let the use select (for example)  
three of five available options presented in a grid component, and  
submit their selections, which are then processed. A good example  
would be a "remove" checkbox on a list of items in a shopping cart,  
where the items are are only in the user's session so database IDs  
won't do.

I've tried looking through the wiki, searching google, searching the  
mailing list with google, and looking through the 'Tapestry 5 Building  
Web Applications' book which I bought as a PDF, but alas, I can't find  
find a simple recipe for doing this.

I'd like to use the Grid because the data will be fairly complex (it  
isn't for the time being, once I get this technique functional it will  
be). I'd like the selection to change a value in the underlying POJO  
(e.g. Pojo.selected) that's backing the Grid. I have been unable to  
get this anywhere near any semblance of "working".  Therefore  
currently any sort of technique that could possibly work would be  
appreciated, for example to have an List<Pojo> originalList and  
List<Pojo> selectedList - I've tried to see what convention might give  
me that behaviour but so far, been unable to uncover it.


scot


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


Re: Using a checkbox in a grid component

Posted by Paulo Ricardo Ribeiro <pa...@gmail.com>.
Olá Thiago :) and Hello Antalk

I've just looked to the demo, and it appears to be exactly what I'm looking
for.

Thank you both for your help

Cheers,
(e um abraço :))
Paulo Ricardo

On Mon, Dec 19, 2011 at 11:38 AM, antalk [via Tapestry] <
ml-node+s1045711n5085856h43@n5.nabble.com> wrote:

> You could checkout my Tapestry Module : Weaves, it has a 'improved' grid
> component with paging and checkboxes per row and also a 'checkall' box.
>
> See: http://intercommitweavesdemo.intercommit.cloudbees.net/pagedgriddemo for
> demo
>
> And: https://github.com/intercommit/Weaves for code
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://tapestry.1045711.n5.nabble.com/Using-a-checkbox-in-a-grid-component-tp2433811p5085856.html
>  To unsubscribe from Using a checkbox in a grid component, click here<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2433811&code=cGF1bG8ucmljYXJkb0BnbWFpbC5jb218MjQzMzgxMXw2NjIyMzQ4OTA=>
> .
> NAML<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

Re: Using a checkbox in a grid component

Posted by antalk <an...@intercommit.nl>.
You could checkout my Tapestry Module : Weaves, it has a 'improved' grid
component with paging and checkboxes per row and also a 'checkall' box.

See: http://intercommitweavesdemo.intercommit.cloudbees.net/pagedgriddemo
for demo

And: https://github.com/intercommit/Weaves for code



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Using-a-checkbox-in-a-grid-component-tp2433811p5085856.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


Re: Using a checkbox in a grid component

Posted by Paulo Ricardo Ribeiro <pa...@gmail.com>.
Hello,

I'm trying to add a "Select All / Select None" button at the end (or top) of
the grid.

I'll, probably create a mixin to do so, but, since i don't want to "reinvent
the wheel", I'm wondering if there's a simple way to do it.

Cheers,
Paulo Ricardo

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Using-a-checkbox-in-a-grid-component-tp2433811p5085754.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


Re: Using a checkbox in a grid component

Posted by Geoff Callender <ge...@gmail.com>.
Here's a working example of a similar technique.

	http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/tables/gridwithdeletecolumn1

HTH,

Geoff

On 11/08/2009, at 7:24 PM, Alfie Kirkpatrick wrote:

> As Sebastian points out if the boolean selected field is part of your
> pojo it is trivial to bind this to a checkbox in the grid. This was my
> initial approach for simplicity but in my case the pojos were  
> Hibernate
> entities and I didn't want this field to be persisted or to clutter up
> the entity as a transient field, so I went with a different approach
> which might work for you...
>
> I created a session-persisted hashset in my page where the elements  
> are
> the ids of the entities being selected (you can use the items  
> themselves
> if they support hashcode/equals properly).
>
> My code looked something like this:
>
> MyPage.java
> -----------
> 	private HashSet<String> selectedSet=new HashSet<String>();
>
> 	public boolean getCurrentSelected() {
> 		return selectedSet.contains(current.getId());
> 	}
> 	
> 	public void setCurrentSelected(boolean value) {
> 		if ( value ) {
> 			selectedSet.add(current.getId());
> 		} else {
> 			selectedSet.remove(current.getId());
> 		}		
> 	}
>
> MyPage.tml
> ----------
> 	<t:grid t:id="selectProgrammesGrid"
> 				source="availsList"
> 				row="current"
> 				add="select">
> 		<p:selectcell>
> 			<t:checkbox value="currentSelected"/>
> 		</p:selectcell>
> 	</t:grid>
>
> Hope it helps, I thought it was rather tidy!
> Alfie.
>
> -----Original Message-----
> From: Scot Mcphee [mailto:scot.mcphee@gmail.com]
> Sent: 10 August 2009 06:41
> To: users@tapestry.apache.org
> Subject: Using a checkbox in a grid component
>
> Hello
>
> Does any one have a short recipe how to use a checkbox in a grid
> component?
>
> What I need to do is fairly simple - let the use select (for example)
> three of five available options presented in a grid component, and
> submit their selections, which are then processed. A good example
> would be a "remove" checkbox on a list of items in a shopping cart,
> where the items are are only in the user's session so database IDs
> won't do.
>
> I've tried looking through the wiki, searching google, searching the
> mailing list with google, and looking through the 'Tapestry 5 Building
> Web Applications' book which I bought as a PDF, but alas, I can't find
> find a simple recipe for doing this.
>
> I'd like to use the Grid because the data will be fairly complex (it
> isn't for the time being, once I get this technique functional it will
> be). I'd like the selection to change a value in the underlying POJO
> (e.g. Pojo.selected) that's backing the Grid. I have been unable to
> get this anywhere near any semblance of "working".  Therefore
> currently any sort of technique that could possibly work would be
> appreciated, for example to have an List<Pojo> originalList and
> List<Pojo> selectedList - I've tried to see what convention might give
> me that behaviour but so far, been unable to uncover it.
>
>
> scot
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


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


RE: Using a checkbox in a grid component

Posted by Alfie Kirkpatrick <Al...@ioko.com>.
As Sebastian points out if the boolean selected field is part of your
pojo it is trivial to bind this to a checkbox in the grid. This was my
initial approach for simplicity but in my case the pojos were Hibernate
entities and I didn't want this field to be persisted or to clutter up
the entity as a transient field, so I went with a different approach
which might work for you...

I created a session-persisted hashset in my page where the elements are
the ids of the entities being selected (you can use the items themselves
if they support hashcode/equals properly).

My code looked something like this:

MyPage.java
-----------
	private HashSet<String> selectedSet=new HashSet<String>();

	public boolean getCurrentSelected() {
		return selectedSet.contains(current.getId());
	}
	
	public void setCurrentSelected(boolean value) {
		if ( value ) {
			selectedSet.add(current.getId());
		} else {
			selectedSet.remove(current.getId());
		}		
	}

MyPage.tml
----------
	<t:grid t:id="selectProgrammesGrid" 
				source="availsList" 
				row="current" 
				add="select">
		<p:selectcell>
			<t:checkbox value="currentSelected"/>
		</p:selectcell>
	</t:grid>

Hope it helps, I thought it was rather tidy!
Alfie.

-----Original Message-----
From: Scot Mcphee [mailto:scot.mcphee@gmail.com] 
Sent: 10 August 2009 06:41
To: users@tapestry.apache.org
Subject: Using a checkbox in a grid component

Hello

Does any one have a short recipe how to use a checkbox in a grid  
component?

What I need to do is fairly simple - let the use select (for example)  
three of five available options presented in a grid component, and  
submit their selections, which are then processed. A good example  
would be a "remove" checkbox on a list of items in a shopping cart,  
where the items are are only in the user's session so database IDs  
won't do.

I've tried looking through the wiki, searching google, searching the  
mailing list with google, and looking through the 'Tapestry 5 Building  
Web Applications' book which I bought as a PDF, but alas, I can't find  
find a simple recipe for doing this.

I'd like to use the Grid because the data will be fairly complex (it  
isn't for the time being, once I get this technique functional it will  
be). I'd like the selection to change a value in the underlying POJO  
(e.g. Pojo.selected) that's backing the Grid. I have been unable to  
get this anywhere near any semblance of "working".  Therefore  
currently any sort of technique that could possibly work would be  
appreciated, for example to have an List<Pojo> originalList and  
List<Pojo> selectedList - I've tried to see what convention might give  
me that behaviour but so far, been unable to uncover it.


scot



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


Re: Using a checkbox in a grid component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 10 Aug 2009 21:42:56 -0300, Scot Mcphee <sc...@gmail.com>  
escreveu:

> BTW Is there any effective difference in using the <t:parameter  
> name="propertynameCell"> style versus the <p:propertynameCell> style of  
> controlling the cell render?

No difference. <t:parameter name="property"> was the first syntax  
provided. The <p:propertyName> is the new one, added in 5.1.0.x.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Using a checkbox in a grid component

Posted by Scot Mcphee <sc...@gmail.com>.

On 10/08/2009, at 23:22 , raucha wrote:

>
> You might not even need any chenillekit on this. I use:
>
>
> <t:parameter name="nameCell">
>  <t:checkbox t:id="name" t:value="row.name"/>
> </t:parameter>


Yes indeed.

In the end I got this to work

   <t:grid source="contacts" row="contact">
     <p:selectedcell>
       <t:checkbox t:id="selected" value="contact.selected" />
     </p:selectedcell>
   </t:grid>

Which is remarkably similar to what I had in the first place. So I  
don't really know what I did wrong in the first instance that led me  
to bolt down a rabbit hole.

BTW Is there any effective difference in using the <t:parameter  
name="propertynameCell"> style versus the <p:propertynameCell> style  
of controlling the cell render?


--
scot.mcphee@gmail.com
http://crazymcphee.net/






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


Re: Using a checkbox in a grid component

Posted by raucha <A....@verband.creditreform.de>.
You might not even need any chenillekit on this. I use:


<t:parameter name="nameCell">
  <t:checkbox t:id="name" t:value="row.name"/>
</t:parameter>


Sebastian Hennebrueder wrote:
> 
> Scot Mcphee schrieb:
>> Hello
>> 
>> Does any one have a short recipe how to use a checkbox in a grid
>> component?
>> 
>> What I need to do is fairly simple - let the use select (for example) 
>> three of five available options presented in a grid component, and 
>> submit their selections, which are then processed. A good example would 
>> be a "remove" checkbox on a list of items in a shopping cart, where the 
>> items are are only in the user's session so database IDs won't do.
>> 
>> I've tried looking through the wiki, searching google, searching the 
>> mailing list with google, and looking through the 'Tapestry 5 Building 
>> Web Applications' book which I bought as a PDF, but alas, I can't find 
>> find a simple recipe for doing this.
>> 
>> I'd like to use the Grid because the data will be fairly complex (it 
>> isn't for the time being, once I get this technique functional it will 
>> be). I'd like the selection to change a value in the underlying POJO 
>> (e.g. Pojo.selected) that's backing the Grid. I have been unable to get 
>> this anywhere near any semblance of "working".  Therefore currently any 
>> sort of technique that could possibly work would be appreciated, for 
>> example to have an List<Pojo> originalList and List<Pojo> selectedList - 
>> I've tried to see what convention might give me that behaviour but so 
>> far, been unable to uncover it.
>> 
>> 
>> scot
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> Here is an example with the chenille components
> http://www.chenillekit.org/chenillekit-tapestry/ref/org/chenillekit/tapestry/core/components/InPlaceEditor.html
> 
> Here is a snippet from my evaluation article, which I will publish this 
> week.
> extract of the template
> <form t:type="form" t:id="addressForm">
> 	<t:errors/>
> 	<t:grid source="addresses" row="address">
> 		<p:nameCell>
> 			<t:hidden value="address.id"/>
> 			<input t:type="TextField" t:id="name" t:value="address.name" 
> t:validate="required, maxlength=10" size="10"/>
> 		</p:nameCell>
> 		<p:cityCell>
> 			<input t:type="TextField" t:id="city" t:value="address.city" 
> t:validate="required, maxlength=10" size="10"/>
> 		</p:cityCell>
> 	</t:grid>
> 	<input type="submit" value="Save"/>
> </form>
> The page class
> public class VariousComponents {
> 
> 	private List<Address> addresses = new ArrayList<Address>();
> 
> 	@Property
> 	private Address address;
> 	
> 	public VariousComponents() {
> 		addresses.add(new Address("foo", "Bad Vilbel", "Germamy", "Bubenweg 
> 1", Salutation.MR));
> 		addresses.add(new Address("bar", "Aachen", "Germamy", "Neuer Weg 1", 
> Salutation.MR));
> 		addresses.add(new Address("bazz", "Frankfurt", "Germamy", "Neuer Weg 
> 2", Salutation.MR));
> 		addresses.add(new Address("bozz", "Chemnitz", "Germamy", "Hase 1", 
> Salutation.MR));
> 		// just set an id value
> 		for(int i = 0; i< addresses.size();i++)
> 			addresses.get(i).setId(i+1);
> 	}
> 
> 	public List<Address> getAddresses() {
> 		return addresses;
> 	}
> }
> 
> 
> -- 
> Best Regards / Viele Grüße
> 
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-a-checkbox-in-a-grid-component-tp24894595p24899653.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


Re: Using a checkbox in a grid component

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Scot Mcphee schrieb:
> Hello
> 
> Does any one have a short recipe how to use a checkbox in a grid component?
> 
> What I need to do is fairly simple - let the use select (for example) 
> three of five available options presented in a grid component, and 
> submit their selections, which are then processed. A good example would 
> be a "remove" checkbox on a list of items in a shopping cart, where the 
> items are are only in the user's session so database IDs won't do.
> 
> I've tried looking through the wiki, searching google, searching the 
> mailing list with google, and looking through the 'Tapestry 5 Building 
> Web Applications' book which I bought as a PDF, but alas, I can't find 
> find a simple recipe for doing this.
> 
> I'd like to use the Grid because the data will be fairly complex (it 
> isn't for the time being, once I get this technique functional it will 
> be). I'd like the selection to change a value in the underlying POJO 
> (e.g. Pojo.selected) that's backing the Grid. I have been unable to get 
> this anywhere near any semblance of "working".  Therefore currently any 
> sort of technique that could possibly work would be appreciated, for 
> example to have an List<Pojo> originalList and List<Pojo> selectedList - 
> I've tried to see what convention might give me that behaviour but so 
> far, been unable to uncover it.
> 
> 
> scot
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
Here is an example with the chenille components
http://www.chenillekit.org/chenillekit-tapestry/ref/org/chenillekit/tapestry/core/components/InPlaceEditor.html

Here is a snippet from my evaluation article, which I will publish this 
week.
extract of the template
<form t:type="form" t:id="addressForm">
	<t:errors/>
	<t:grid source="addresses" row="address">
		<p:nameCell>
			<t:hidden value="address.id"/>
			<input t:type="TextField" t:id="name" t:value="address.name" 
t:validate="required, maxlength=10" size="10"/>
		</p:nameCell>
		<p:cityCell>
			<input t:type="TextField" t:id="city" t:value="address.city" 
t:validate="required, maxlength=10" size="10"/>
		</p:cityCell>
	</t:grid>
	<input type="submit" value="Save"/>
</form>
The page class
public class VariousComponents {

	private List<Address> addresses = new ArrayList<Address>();

	@Property
	private Address address;
	
	public VariousComponents() {
		addresses.add(new Address("foo", "Bad Vilbel", "Germamy", "Bubenweg 
1", Salutation.MR));
		addresses.add(new Address("bar", "Aachen", "Germamy", "Neuer Weg 1", 
Salutation.MR));
		addresses.add(new Address("bazz", "Frankfurt", "Germamy", "Neuer Weg 
2", Salutation.MR));
		addresses.add(new Address("bozz", "Chemnitz", "Germamy", "Hase 1", 
Salutation.MR));
		// just set an id value
		for(int i = 0; i< addresses.size();i++)
			addresses.get(i).setId(i+1);
	}

	public List<Address> getAddresses() {
		return addresses;
	}
}


-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



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