You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Rich M <ri...@moremagic.com> on 2010/11/02 23:33:27 UTC

Getting form client input to persist through zone update

Hi,

so I've had to add some mixins to a form to conditionally handle some 
form elements based on used input. A user selects a certain select list 
option, some fields get disabled or enabled as a result type thing.

The form is actually a BeanEditForm, not just a Form. Anyway, when my 
mixin returns back to the Page class event method which in turn updates 
the Zone, I lose all the values the user filled out in the form. 
Understandable enough, they were only living on the client side until 
the mixin-zone update occurred. As far as I recall Zones embedded in 
Forms don't really work out, hence my zone wraps around the form in its 
entirety.

Is there a good way to deal with this scenario? I was thinking there 
might be some way to tap into the binding to the Bean object that the 
BeanEditForm does during form submission. That would be ideal. I think 
the onPrepareFromForm method does what I want:

 From BeanEditForm.java @ line 141

void onPrepareFromForm()
     {
         resources.triggerEvent(EventConstants.PREPARE, null, null);

         if (model == null)
         {
             Class beanType = resources.getBoundType("object");

             model = beanModelSource.createEditModel(beanType, resources.getContainerMessages());

             BeanModelUtils.modify(model, add, include, exclude, reorder);
         }
     }

Of course it's calling some internals and I don't think I can just do 
this from my page class. Is there some way to get the BeanEditForm to 
store the form values into the property bindings?


Also, I know it's possible to pass all the form values through as 
request parameters via AJAX and copy them into the property bindings of 
the form elements manually, but that seems pretty excessive. I hope 
that's not my best option =/.

Thanks,
Rich

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


Re: Getting form client input to persist through zone update

Posted by Rich M <ri...@moremagic.com>.
Hi,

I guess that works. I was trying to avoid managing the fields explicitly 
in javascript, but that seems like the quickest solution and not too 
harmful for this use case. Got it working doing that, so that's great.

I have a further question though. I also have an edit page for this Bean 
entity, and on this page I need to update the selection of a Select 
component during rendering, or more likely in a way that appears to the 
user to have been during rendering. I have a database field that cannot 
directly map to the select list values, so I need some intermediate 
parsing to delegate the proper values to the Select component's value.

What I thought would work is it have a mixin on the field, pass 
parameters to this so it can fire a page class event that updates a zone 
body. When the mixin's javascript class object gets initialized, I had 
it call a method that should fire the page class event. The problem I'm 
running into is that it seems Tapestry places the initialization of the 
mixins before the call to Tapestry.init(...). The javascript in the page 
ends up looking like this:

<script type="text/javascript">Tapestry.onDOMLoaded(function() {
someMixin = new someMixin(...)
Tapestry.init(...)
</script>

The issue here being that the zoneManager isn't initialized for the page 
until Tapestry.init(...), yet I want to access it during the 
instantiation of someMixin.

Is there any way to achieve this, or perhaps a better solution?

Thanks,
Rich

On 11/02/2010 07:49 PM, Thiago H. de Paula Figueiredo wrote:
> On Tue, 02 Nov 2010 20:33:27 -0200, Rich M <ri...@moremagic.com> wrote:
>
>> Hi,
>
> Hi!
>
>> so I've had to add some mixins to a form to conditionally handle some 
>> form elements based on used input. A user selects a certain select 
>> list option, some fields get disabled or enabled as a result type thing.
>
> Does all this logic need to be implemented server-side? If yes and 
> they invole a little amount of data, you can generate JavaScript to 
> handle all this client-side.
>
> Have you thought about doing a triggering an event using a little bit 
> of JavaScript and make return a JSONObject or JSONArray in your event 
> handler method containing the needed data?
>
>> Also, I know it's possible to pass all the form values through as 
>> request parameters via AJAX
>
> Yes. See http://api.prototypejs.org/ajax/ajax/request/, 
> http://api.prototypejs.org/dom/form/serialize/, 
> http://api.prototypejs.org/dom/form/request/ and 
> http://madchicken.altervista.org/js/deserialize.js (found here: 
> http://madchicken.altervista.org/tech/2006/02/prototype-form-serialization-and.html). 
> If you're using another JavaScript framework it probably offers 
> something like that too.
>
>> and copy them into the property bindings of the form elements 
>> manually, but that seems pretty excessive.
>
> You won't need that. Just submit the form by JavaScript and Tapestry 
> will set the properties.
>
>> I hope that's not my best option =/.
>
> IMHO, your scenario is quite specific, so you'll need custom 
> JavaScript. You want to submit a form and update some fields but not 
> others.
>


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


Re: Getting form client input to persist through zone update

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 02 Nov 2010 20:33:27 -0200, Rich M <ri...@moremagic.com> wrote:

> Hi,

Hi!

> so I've had to add some mixins to a form to conditionally handle some  
> form elements based on used input. A user selects a certain select list  
> option, some fields get disabled or enabled as a result type thing.

Does all this logic need to be implemented server-side? If yes and they  
invole a little amount of data, you can generate JavaScript to handle all  
this client-side.

Have you thought about doing a triggering an event using a little bit of  
JavaScript and make return a JSONObject or JSONArray in your event handler  
method containing the needed data?

> Also, I know it's possible to pass all the form values through as  
> request parameters via AJAX

Yes. See http://api.prototypejs.org/ajax/ajax/request/,  
http://api.prototypejs.org/dom/form/serialize/,  
http://api.prototypejs.org/dom/form/request/ and  
http://madchicken.altervista.org/js/deserialize.js (found here:  
http://madchicken.altervista.org/tech/2006/02/prototype-form-serialization-and.html).  
If you're using another JavaScript framework it probably offers something  
like that too.

> and copy them into the property bindings of the form elements manually,  
> but that seems pretty excessive.

You won't need that. Just submit the form by JavaScript and Tapestry will  
set the properties.

> I hope that's not my best option =/.

IMHO, your scenario is quite specific, so you'll need custom JavaScript.  
You want to submit a form and update some fields but not others.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, 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