Thanks Josh, I guess my approach was probably wrong to begin with, but this 
looks good, will give it a try. I also agree the checkbox could do with another 
attribute perhaps a context? which would make it a little easier to work with. 

Thanks everyone for your responses!
Peter

----- Original Message -----
From: "Josh Canfield" <[EMAIL PROTECTED]>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Thursday, 24 April, 2008 9:44:40 PM GMT +02:00 Athens, Beirut, Bucharest, 
Istanbul
Subject: Re: How to update a list from a checkbox in a loop in t5

The way checkbox works out of the box you need to coordinate with the
loop via the index or value parameter, as others have suggested. This
works but can be dangerous if your loop source happens to change
between the form render and the form submit. Try this extension so you
can bind a data value to the checkbox.

import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.corelib.components.Checkbox;
import org.apache.tapestry.ioc.annotations.Inject;

/**
 * <t:datacheckbox t:value="checked" t:data="data" />
 */
public class DataCheckbox extends Checkbox {

        @Parameter
        private String _data;
        
        @Inject
        private org.apache.tapestry.services.Request _request;
        protected void beforeRenderTemplate(MarkupWriter writer) {
                writer.attributes("value", _data);
        }
        
        @Override
        protected void processSubmission(String elementName) {
                super.processSubmission(elementName);
                String value = _request.getParameter(elementName);
                if ( value != null ) {
                        _data = value;
                }
        }
}

You still have to provide the boolean value, but you can now also
provide a data parameter. While the boolean parameter will get set for
every instance of the checkbox, this extension only gets set if the
checkbox was checked.

I'd love to see the core checkbox component support more than boolean values...
Josh

On Thu, Apr 24, 2008 at 3:59 AM, Peter Stavrinides
<[EMAIL PROTECTED]> wrote:
> Hi Nicholas
>
> This is simply boilerplate code:
> <t:loop source="myDOA" value="selectedDOA" encoder="encoder">
>      <t:checkbox t:id="archived" value="archive" />
> </t:loop>
>
>
> Archive is a read only boolean (no setter permitted), no model or encoder is 
> available, which = no easy way to update like say if this was a textfield, 
> making the checkbox not very useful in a loop!
>
> Peter
>
>
>
> ----- Original Message -----
> From: "nicholas Krul" <[EMAIL PROTECTED]>
> To: "Tapestry users" <users@tapestry.apache.org>
> Sent: Thursday, 24 April, 2008 1:13:44 PM GMT +02:00 Athens, Beirut, 
> Bucharest, Istanbul
> Subject: Re: How to update a list from a checkbox in a loop in t5
>
> Perhaps some code would help us out.
>
> .tml loop & checkbox snippet
>
> .java index & getter & setter snippet
>
>
> ? I can only try
>
> On Thu, Apr 24, 2008 at 10:54 AM, Peter Stavrinides <
> [EMAIL PROTECTED]> wrote:
>
> > I have also noticed that the value parameter on the checkbox component is
> > a read only boolean, so using accessors to write the value is impossible,
> > which confirms the checkbox is not usable in this way in a loop.
> >
> >
> > Peter Stavrinides wrote:
> >
> > > Sorry, let me try rephrasing my question:
> > >
> > > When I click on the checkbox, how do I modify the corresponding object
> > > in the loop? The only way I can see of doing this is to iterate manually, 
> > > in
> > > which case a Tapestry checkbox component is not usable in a loop.
> > >
> > > Peter
> > >
> > > Peter Stavrinides wrote:
> > >
> > > > Hi All
> > > >
> > > > I this scenario:
> > > > <t:loop source="myDOA" value="selectedDOA" encoder="encoder">
> > > >           <t:checkbox t:id="archived" />
> > > > </t:loop>
> > > >
> > > > How do I use the checkbox correctly when the user clicks it? 'I want
> > > > to associate it with an object' via a primary key perhaps...but the 
> > > > checkbox
> > > > only seems to have a value property of the type boolean:
> > > >
> > > >
> > > > http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/Checkbox.html
> > > >
> > > > Sorry if this question seems trivial, but I have been scratching my
> > > > head for a while now.
> > > >
> > > > thanks,
> > > > Peter
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

---------------------------------------------------------------------
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