You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jaques robert <mo...@yahoo.fr> on 2010/04/07 18:16:46 UTC

Re: Persist value of checkbox ?

<<
  And then in your onSuccess() and/or onValidate() event handler
method,
 you can inject the Request get get the selectedObjects query
parameter
 value.

>>

Have you got sample code about this ?

Regards.

--- En date de : Lun 29.3.10, Howard Lewis Ship <hl...@gmail.com> a écrit :

De: Howard Lewis Ship <hl...@gmail.com>
Objet: Re: Persist value of checkbox ?
À: "Tapestry users" <us...@tapestry.apache.org>
Date: Lundi 29 mars 2010, 18h45

On Mon, Mar 29, 2010 at 9:14 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 29 Mar 2010 13:10:15 -0300, jaques robert
> <mo...@yahoo.fr> wrote:
>
>> Hello,
>
> Hi!
>
>> I've tried this code which present 10 checkbox which I submit. Then I go
>> back to this page so I'd like those checkbox to be ticked if they were
>> ticked before.
>>
>>        <t:Loop source="1..10" value="index">
>>            <input t:type="checkbox" t:id="pute" />
>>        </t:Loop>
>>
>> So in my class I've coded :
>>    @Persist
>>    @Property
>>    private boolean _pute;
>
> You should have a list of booleans, not a single one.

To amplify here, Tapestry is doing what you told it to.  It renders 10
checkboxes, each of which draws its initial value from the _pute field
(and pute property).

On submit, it does the exact same thing: reads the query parameter for
each checkbox (they get rendered with unique name attributes) and
updates the pute property. However, since there's 10 checkboxes and
only one property, it ends up with the 10th checkbox's value.

I teach, in my labs, a way to use a synthetic property to populate a
Set with value selected by checkboxes .... but you could just as
easily use ordinary HTML <input type="checkbox">, assign your own name
and use a value (typically a database persistent entity id) of your
own devising:

  <t:loop source="databaseObjects" value="object">
    <input type="checkbox" name="selectedObjects" value="${object.id}"/> ...
  </t:loop>

  And then in your onSuccess() and/or onValidate() event handler
method, you can inject the Request get get the selectedObjects query
parameter value.


 I call this "dropping down to Servlets mode" and it is appropriate in
cases where a full-bore Tapestry component solution is more work.

>
>
>> private Object onSuccess() {
>>        // call database update
>>        return this;
>>    }
>
> Return null instead.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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




      

Re: Persist value of checkbox ?

Posted by jaques robert <mo...@yahoo.fr>.
I've finally found it using 
    @Inject
    private RequestGlobals requestGlobals;

Now I'd like to pass a context to my page, fetch the name of checkbox I'd like to tick. So I've tried this kind of code in the onActivate :
void onActivate(String exportNameForModification) {
        _exportNameForModifcation = exportNameForModification;
        System.out.println("_exportNameForModifcation : " + _exportNameForModifcation);
        List<ExportDocumentField> documentFieldAlreadyTicked = getExportService().getDocumentFields(exportNameForModification);
        
        HttpServletRequest req = requestGlobals.getHTTPServletRequest();
        List<String> selectedDocumentFields = new LinkedList<String>();
        
        
        for (ExportDocumentField edf : documentFieldAlreadyTicked) {
            selectedDocumentFields.add(edf.getDocumentFieldDN());
        }
        req.setAttribute("selectedDocumentFields", selectedDocumentFields.toArray());
    }

However the checkbox are not checked :( ... Do you know a way to do that ?

Regards,
Mondes_engloutis.

--- En date de : Mer 7.4.10, jaques robert <mo...@yahoo.fr> a écrit :

De: jaques robert <mo...@yahoo.fr>
Objet: Re: Persist value of checkbox ?
À: "Tapestry users" <us...@tapestry.apache.org>
Date: Mercredi 7 avril 2010, 18h16

<<
  And then in your onSuccess() and/or onValidate() event handler
method,
 you can inject the Request get get the selectedObjects query
parameter
 value.

>>

Have you got sample code about this ?

Regards.

--- En date de : Lun 29.3.10, Howard Lewis Ship <hl...@gmail.com> a écrit :

De: Howard Lewis Ship <hl...@gmail.com>
Objet: Re: Persist value of checkbox ?
À: "Tapestry users" <us...@tapestry.apache.org>
Date: Lundi 29 mars 2010, 18h45

On Mon, Mar 29, 2010 at 9:14 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 29 Mar 2010 13:10:15 -0300, jaques robert
> <mo...@yahoo.fr> wrote:
>
>> Hello,
>
> Hi!
>
>> I've tried this code which present 10 checkbox which I submit. Then I go
>> back to this page so I'd like those checkbox to be ticked if they were
>> ticked before.
>>
>>        <t:Loop source="1..10" value="index">
>>            <input t:type="checkbox" t:id="pute" />
>>        </t:Loop>
>>
>> So in my class I've coded :
>>    @Persist
>>    @Property
>>    private boolean _pute;
>
> You should have a list of booleans, not a single one.

To amplify here, Tapestry is doing what you told it to.  It renders 10
checkboxes, each of which draws its initial value from the _pute field
(and pute property).

On submit, it does the exact same thing: reads the query parameter for
each checkbox (they get rendered with unique name attributes) and
updates the pute property. However, since there's 10 checkboxes and
only one property, it ends up with the 10th checkbox's value.

I teach, in my labs, a way to use a synthetic property to populate a
Set with value selected by checkboxes .... but you could just as
easily use ordinary HTML <input type="checkbox">, assign your own name
and use a value (typically a database persistent entity id) of your
own devising:

  <t:loop source="databaseObjects" value="object">
    <input type="checkbox" name="selectedObjects" value="${object.id}"/> ...
  </t:loop>

  And then in your onSuccess() and/or onValidate() event handler
method, you can inject the Request get get the selectedObjects query
parameter value.


 I call this "dropping down to Servlets mode" and it is appropriate in
cases where a full-bore Tapestry component solution is more work.

>
>
>> private Object onSuccess() {
>>        // call database update
>>        return this;
>>    }
>
> Return null instead.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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