You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Beat Durrer <bd...@gmail.com> on 2012/03/05 11:47:55 UTC

Select Component chaining: 2nd select box value is always null

Hey there

For my project I need two chained select boxes.
I followed the example shown in the API
(http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html),
but used my own SelectModel for my custom value type.

It all looks nice, but when I submit the form, the second select box
is always null.
When I add a @Validate("required") on both fields, the client
validation is happy with the boxes, but the server side validation
fails.
I added some debug output and of course the value turns out to be null
in onValidate()

Using Firebug I noticed that the second select in the zone changes its
name and id each time the zone updates, it's something like
"carModel_135e275b957"

Which leads me to the question: What did I do wrong? I never worked
with zones before, so do I need to do some kind of special handling?


Cheers and thanks in advance
Beat

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


Re: Select Component chaining: 2nd select box value is always null

Posted by Beat Durrer <bd...@gmail.com>.
Thanks for that Link, it got me thinking and solved my issue :)

A missing @Persist on the property combined with an onActivate method
which always resetted the ValueEncoder/SelectModel was the issue.
My data comes out of a Database, I wrote a ValueEncoder which only
holds the values of the current carMaker subset.

kind of a chicken-egg-dilemma:
You need the encoder to get the value of the first select box, on the
other hand you need the value to determine how to resolve the value of
the second select box.


Thank you all for your help :)


2012/3/5 Muhammad Gelbana <m....@gmail.com>:
> Just a wild guess. If any method is called before validating the form
> returns a value that should re-post the form, your field will be null if
> it's not persisted.
>
> So for example, is the submit button handling method returning anything or
> is it void ?
> Try *@Persist*ing your field, if it's not null, then my guess is probably
> right.
>
> This link may prove helpful:
> http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/whatiscalledandwhen
>
>
> On Mon, Mar 5, 2012 at 1:00 PM, Beat Durrer <bd...@gmail.com> wrote:
>
>> Hi Giulio,
>>
>> No, they are not. The form is really straight forward as in the example:
>>
>>
>> <t:form t:id="applicationForm" >
>>      <t:errors/>
>>
>>     <div  class="form-row">
>>        <div class="twoColumnFirst">
>>           <t:select t:id="category" model="categoryModel"
>> encoder="categoryModel" blankOption="ALWAYS"
>>              value="categoryItem" zone="subCategoryZone"/>
>>        </div>
>>        <div class="twoColumnSecond" t:type="zone"
>> t:id="subCategoryZone" id="subCategoryZone">
>>              <t:select t:id="subCategory" value="subCategoryItem"
>>                 model="subCategoryModel" encoder="subCategoryModel"/>
>>        </div>
>>     </div>
>>
>>    <div class="form-row">
>>       <a t:type="LinkSubmit" t:id="forward" class="button
>> button-prim">Next</a>
>>    </div>
>> </t:form>
>>
>>
>>
>>
>>
>> 2012/3/5 Giulio Micali <gi...@gmail.com>:
>> > Are your selects in a loop ?
>> >
>> >
>> >
>> > 2012/3/5 Beat Durrer <bd...@gmail.com>
>> >
>> >> Hey there
>> >>
>> >> For my project I need two chained select boxes.
>> >> I followed the example shown in the API
>> >> (
>> >>
>> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html
>> >> ),
>> >> but used my own SelectModel for my custom value type.
>> >>
>> >> It all looks nice, but when I submit the form, the second select box
>> >> is always null.
>> >> When I add a @Validate("required") on both fields, the client
>> >> validation is happy with the boxes, but the server side validation
>> >> fails.
>> >> I added some debug output and of course the value turns out to be null
>> >> in onValidate()
>> >>
>> >> Using Firebug I noticed that the second select in the zone changes its
>> >> name and id each time the zone updates, it's something like
>> >> "carModel_135e275b957"
>> >>
>> >> Which leads me to the question: What did I do wrong? I never worked
>> >> with zones before, so do I need to do some kind of special handling?
>> >>
>> >>
>> >> Cheers and thanks in advance
>> >> Beat
>> >>
>> >> ---------------------------------------------------------------------
>> >> 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
>>
>>
>
>
> --
> *Regards,*
> *Muhammad Gelbana
> Java Developer*

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


Re: Select Component chaining: 2nd select box value is always null

Posted by Muhammad Gelbana <m....@gmail.com>.
Just a wild guess. If any method is called before validating the form
returns a value that should re-post the form, your field will be null if
it's not persisted.

So for example, is the submit button handling method returning anything or
is it void ?
Try *@Persist*ing your field, if it's not null, then my guess is probably
right.

This link may prove helpful:
http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/whatiscalledandwhen


On Mon, Mar 5, 2012 at 1:00 PM, Beat Durrer <bd...@gmail.com> wrote:

> Hi Giulio,
>
> No, they are not. The form is really straight forward as in the example:
>
>
> <t:form t:id="applicationForm" >
>      <t:errors/>
>
>     <div  class="form-row">
>        <div class="twoColumnFirst">
>           <t:select t:id="category" model="categoryModel"
> encoder="categoryModel" blankOption="ALWAYS"
>              value="categoryItem" zone="subCategoryZone"/>
>        </div>
>        <div class="twoColumnSecond" t:type="zone"
> t:id="subCategoryZone" id="subCategoryZone">
>              <t:select t:id="subCategory" value="subCategoryItem"
>                 model="subCategoryModel" encoder="subCategoryModel"/>
>        </div>
>     </div>
>
>    <div class="form-row">
>       <a t:type="LinkSubmit" t:id="forward" class="button
> button-prim">Next</a>
>    </div>
> </t:form>
>
>
>
>
>
> 2012/3/5 Giulio Micali <gi...@gmail.com>:
> > Are your selects in a loop ?
> >
> >
> >
> > 2012/3/5 Beat Durrer <bd...@gmail.com>
> >
> >> Hey there
> >>
> >> For my project I need two chained select boxes.
> >> I followed the example shown in the API
> >> (
> >>
> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html
> >> ),
> >> but used my own SelectModel for my custom value type.
> >>
> >> It all looks nice, but when I submit the form, the second select box
> >> is always null.
> >> When I add a @Validate("required") on both fields, the client
> >> validation is happy with the boxes, but the server side validation
> >> fails.
> >> I added some debug output and of course the value turns out to be null
> >> in onValidate()
> >>
> >> Using Firebug I noticed that the second select in the zone changes its
> >> name and id each time the zone updates, it's something like
> >> "carModel_135e275b957"
> >>
> >> Which leads me to the question: What did I do wrong? I never worked
> >> with zones before, so do I need to do some kind of special handling?
> >>
> >>
> >> Cheers and thanks in advance
> >> Beat
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>


-- 
*Regards,*
*Muhammad Gelbana
Java Developer*

Re: Select Component chaining: 2nd select box value is always null

Posted by Beat Durrer <bd...@gmail.com>.
Hi Giulio,

No, they are not. The form is really straight forward as in the example:


<t:form t:id="applicationForm" >
      <t:errors/>

     <div  class="form-row">
        <div class="twoColumnFirst">
           <t:select t:id="category" model="categoryModel"
encoder="categoryModel" blankOption="ALWAYS"
              value="categoryItem" zone="subCategoryZone"/>
        </div>
        <div class="twoColumnSecond" t:type="zone"
t:id="subCategoryZone" id="subCategoryZone">
              <t:select t:id="subCategory" value="subCategoryItem"
                 model="subCategoryModel" encoder="subCategoryModel"/>
        </div>
     </div>

    <div class="form-row">
       <a t:type="LinkSubmit" t:id="forward" class="button button-prim">Next</a>
    </div>
</t:form>





2012/3/5 Giulio Micali <gi...@gmail.com>:
> Are your selects in a loop ?
>
>
>
> 2012/3/5 Beat Durrer <bd...@gmail.com>
>
>> Hey there
>>
>> For my project I need two chained select boxes.
>> I followed the example shown in the API
>> (
>> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html
>> ),
>> but used my own SelectModel for my custom value type.
>>
>> It all looks nice, but when I submit the form, the second select box
>> is always null.
>> When I add a @Validate("required") on both fields, the client
>> validation is happy with the boxes, but the server side validation
>> fails.
>> I added some debug output and of course the value turns out to be null
>> in onValidate()
>>
>> Using Firebug I noticed that the second select in the zone changes its
>> name and id each time the zone updates, it's something like
>> "carModel_135e275b957"
>>
>> Which leads me to the question: What did I do wrong? I never worked
>> with zones before, so do I need to do some kind of special handling?
>>
>>
>> Cheers and thanks in advance
>> Beat
>>
>> ---------------------------------------------------------------------
>> 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: Select Component chaining: 2nd select box value is always null

Posted by Giulio Micali <gi...@gmail.com>.
Are your selects in a loop ?



2012/3/5 Beat Durrer <bd...@gmail.com>

> Hey there
>
> For my project I need two chained select boxes.
> I followed the example shown in the API
> (
> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html
> ),
> but used my own SelectModel for my custom value type.
>
> It all looks nice, but when I submit the form, the second select box
> is always null.
> When I add a @Validate("required") on both fields, the client
> validation is happy with the boxes, but the server side validation
> fails.
> I added some debug output and of course the value turns out to be null
> in onValidate()
>
> Using Firebug I noticed that the second select in the zone changes its
> name and id each time the zone updates, it's something like
> "carModel_135e275b957"
>
> Which leads me to the question: What did I do wrong? I never worked
> with zones before, so do I need to do some kind of special handling?
>
>
> Cheers and thanks in advance
> Beat
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>