You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Muhammad Gelbana <m....@gmail.com> on 2014/07/12 15:55:21 UTC

[t5.4-beta-6] Page class member variable scope

I hope I selected a valid subject !

When I handle a VALUE_CHANGED event for a Select component. I receive the
current value for the Select component as an event handler method parameter.

I use this parameter to set a member variable in the page's class.

@OnEvent(component = "parameterType", value = EventConstants.VALUE_CHANGED)
> private Object pairParameterTypeChanged(ChariotTestTypePairParameterType
> selectedType) {
> this.parameterType = selectedType;
> System.out.println("Type1: " + this.parameterType);
> return this;
> }


In another part of the page, I use a Delegate to conditionally display a
block.

public Block getPairParameterInputBlock() {
> System.out.println("Type2: " + this.parameterType);
> if (this.parameterType == null) {
> return null;
> }
> switch (this.parameterType) {
> case TEXT:
> return this.textPairParameterInput;
> case NUMERIC:
> return this.numericPairParameterInput;
> default:
> return null;
> }
> }


What I'm facing there is that *this.parameterType* is always null and never
sees the value set to it in the Select component's event handler method !

I understand there could be other ways to achieve the same behavior but why
isn't this behaving as I expect ?

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana

Re: [t5.4-beta-6] Page class member variable scope

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sun, 13 Jul 2014 04:44:04 -0300, Geoff Callender  
<ge...@gmail.com> wrote:

> By returning "this" you're doing a page refresh, which is an HTTP 302  
> redirect, instead of an AJAX response.

So never return "this" in an event handler method unless you're really  
sure you want to force a full page refresh, and in almost 99% of the time  
you don't. :)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: [t5.4-beta-6] Page class member variable scope

Posted by Muhammad Gelbana <m....@gmail.com>.
Exactly. I was thinking of a *submit*. But now that I thought about it, a
submit may not be needed. But I tend prefer having every possible option
available for me to handle whatever scenario I may face. I'll go with the
ajax option. Thank you.

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Sun, Jul 13, 2014 at 12:26 PM, Geoff Callender <
geoff.callender.jumpstart@gmail.com> wrote:

> Sorry, that sounds very odd to me. "refresh the page without refreshing
> it" sounds like a contradiction!
>
> Your Select has made an AJAX request. Why wouldn't you want an AJAX
> response, ie. a partial render? If you return the whole page then any other
> changes on the client-side will be overwritten, by a server that doesn't
> know what was there except for the value of the Select and any context.
>
> Your question is making me think what you really want is to trigger a
> submit of the enclosing form when the Select value changes. That way the
> server-side will get the whole picture and be able to do a suitable
> non-AJAX response.
>
> On 13 Jul 2014, at 8:06 pm, Muhammad Gelbana <m....@gmail.com> wrote:
>
> > ​Its ok to use Ajax, but is it the only way to update the page after a
> > value is changed in a Select component ? If yes, wouldn't it be an
> > improvement to be able to refresh the page​ without refreshing it and
> > losing its state ?
> >
> > *---------------------*
> > *Muhammad Gelbana*
> > http://www.linkedin.com/in/mgelbana
> >
> >
> > On Sun, Jul 13, 2014 at 9:44 AM, Geoff Callender <
> > geoff.callender.jumpstart@gmail.com> wrote:
> >
> >> By returning "this" you're doing a page refresh, which is an HTTP 302
> >> redirect, instead of an AJAX response.
> >>
> >> The redirect causes the browser to issue a second request - a fresh page
> >> request - which will be freshly rendered by your stateless page class
> >> without any knowledge of the value you set in the previous request. You
> can
> >> see the 302 response and the second request with the browser's web
> >> inspector or firebug.
> >>
> >> Here's a working example:
> >>
> >>
> >> http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/select1
> >>
> >> Cheers,
> >>
> >> Geoff
> >>
> >> On 12 Jul 2014, at 11:55 pm, Muhammad Gelbana <m....@gmail.com>
> wrote:
> >>
> >>> I hope I selected a valid subject !
> >>>
> >>> When I handle a VALUE_CHANGED event for a Select component. I receive
> the
> >>> current value for the Select component as an event handler method
> >> parameter.
> >>>
> >>> I use this parameter to set a member variable in the page's class.
> >>>
> >>> @OnEvent(component = "parameterType", value =
> >> EventConstants.VALUE_CHANGED)
> >>>> private Object
> pairParameterTypeChanged(ChariotTestTypePairParameterType
> >>>> selectedType) {
> >>>> this.parameterType = selectedType;
> >>>> System.out.println("Type1: " + this.parameterType);
> >>>> return this;
> >>>> }
> >>>
> >>>
> >>> In another part of the page, I use a Delegate to conditionally display
> a
> >>> block.
> >>>
> >>> public Block getPairParameterInputBlock() {
> >>>> System.out.println("Type2: " + this.parameterType);
> >>>> if (this.parameterType == null) {
> >>>> return null;
> >>>> }
> >>>> switch (this.parameterType) {
> >>>> case TEXT:
> >>>> return this.textPairParameterInput;
> >>>> case NUMERIC:
> >>>> return this.numericPairParameterInput;
> >>>> default:
> >>>> return null;
> >>>> }
> >>>> }
> >>>
> >>>
> >>> What I'm facing there is that *this.parameterType* is always null and
> >> never
> >>> sees the value set to it in the Select component's event handler
> method !
> >>>
> >>> I understand there could be other ways to achieve the same behavior but
> >> why
> >>> isn't this behaving as I expect ?
> >>>
> >>> *---------------------*
> >>> *Muhammad Gelbana*
> >>> http://www.linkedin.com/in/mgelbana
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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: [t5.4-beta-6] Page class member variable scope

Posted by Geoff Callender <ge...@gmail.com>.
Sorry, that sounds very odd to me. "refresh the page without refreshing it" sounds like a contradiction!

Your Select has made an AJAX request. Why wouldn't you want an AJAX response, ie. a partial render? If you return the whole page then any other changes on the client-side will be overwritten, by a server that doesn't know what was there except for the value of the Select and any context.

Your question is making me think what you really want is to trigger a submit of the enclosing form when the Select value changes. That way the server-side will get the whole picture and be able to do a suitable non-AJAX response.

On 13 Jul 2014, at 8:06 pm, Muhammad Gelbana <m....@gmail.com> wrote:

> ​Its ok to use Ajax, but is it the only way to update the page after a
> value is changed in a Select component ? If yes, wouldn't it be an
> improvement to be able to refresh the page​ without refreshing it and
> losing its state ?
> 
> *---------------------*
> *Muhammad Gelbana*
> http://www.linkedin.com/in/mgelbana
> 
> 
> On Sun, Jul 13, 2014 at 9:44 AM, Geoff Callender <
> geoff.callender.jumpstart@gmail.com> wrote:
> 
>> By returning "this" you're doing a page refresh, which is an HTTP 302
>> redirect, instead of an AJAX response.
>> 
>> The redirect causes the browser to issue a second request - a fresh page
>> request - which will be freshly rendered by your stateless page class
>> without any knowledge of the value you set in the previous request. You can
>> see the 302 response and the second request with the browser's web
>> inspector or firebug.
>> 
>> Here's a working example:
>> 
>> 
>> http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/select1
>> 
>> Cheers,
>> 
>> Geoff
>> 
>> On 12 Jul 2014, at 11:55 pm, Muhammad Gelbana <m....@gmail.com> wrote:
>> 
>>> I hope I selected a valid subject !
>>> 
>>> When I handle a VALUE_CHANGED event for a Select component. I receive the
>>> current value for the Select component as an event handler method
>> parameter.
>>> 
>>> I use this parameter to set a member variable in the page's class.
>>> 
>>> @OnEvent(component = "parameterType", value =
>> EventConstants.VALUE_CHANGED)
>>>> private Object pairParameterTypeChanged(ChariotTestTypePairParameterType
>>>> selectedType) {
>>>> this.parameterType = selectedType;
>>>> System.out.println("Type1: " + this.parameterType);
>>>> return this;
>>>> }
>>> 
>>> 
>>> In another part of the page, I use a Delegate to conditionally display a
>>> block.
>>> 
>>> public Block getPairParameterInputBlock() {
>>>> System.out.println("Type2: " + this.parameterType);
>>>> if (this.parameterType == null) {
>>>> return null;
>>>> }
>>>> switch (this.parameterType) {
>>>> case TEXT:
>>>> return this.textPairParameterInput;
>>>> case NUMERIC:
>>>> return this.numericPairParameterInput;
>>>> default:
>>>> return null;
>>>> }
>>>> }
>>> 
>>> 
>>> What I'm facing there is that *this.parameterType* is always null and
>> never
>>> sees the value set to it in the Select component's event handler method !
>>> 
>>> I understand there could be other ways to achieve the same behavior but
>> why
>>> isn't this behaving as I expect ?
>>> 
>>> *---------------------*
>>> *Muhammad Gelbana*
>>> http://www.linkedin.com/in/mgelbana
>> 
>> 
>> ---------------------------------------------------------------------
>> 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: [t5.4-beta-6] Page class member variable scope

Posted by Muhammad Gelbana <m....@gmail.com>.
​Its ok to use Ajax, but is it the only way to update the page after a
value is changed in a Select component ? If yes, wouldn't it be an
improvement to be able to refresh the page​ without refreshing it and
losing its state ?

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Sun, Jul 13, 2014 at 9:44 AM, Geoff Callender <
geoff.callender.jumpstart@gmail.com> wrote:

> By returning "this" you're doing a page refresh, which is an HTTP 302
> redirect, instead of an AJAX response.
>
> The redirect causes the browser to issue a second request - a fresh page
> request - which will be freshly rendered by your stateless page class
> without any knowledge of the value you set in the previous request. You can
> see the 302 response and the second request with the browser's web
> inspector or firebug.
>
> Here's a working example:
>
>
> http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/select1
>
> Cheers,
>
> Geoff
>
> On 12 Jul 2014, at 11:55 pm, Muhammad Gelbana <m....@gmail.com> wrote:
>
> > I hope I selected a valid subject !
> >
> > When I handle a VALUE_CHANGED event for a Select component. I receive the
> > current value for the Select component as an event handler method
> parameter.
> >
> > I use this parameter to set a member variable in the page's class.
> >
> > @OnEvent(component = "parameterType", value =
> EventConstants.VALUE_CHANGED)
> >> private Object pairParameterTypeChanged(ChariotTestTypePairParameterType
> >> selectedType) {
> >> this.parameterType = selectedType;
> >> System.out.println("Type1: " + this.parameterType);
> >> return this;
> >> }
> >
> >
> > In another part of the page, I use a Delegate to conditionally display a
> > block.
> >
> > public Block getPairParameterInputBlock() {
> >> System.out.println("Type2: " + this.parameterType);
> >> if (this.parameterType == null) {
> >> return null;
> >> }
> >> switch (this.parameterType) {
> >> case TEXT:
> >> return this.textPairParameterInput;
> >> case NUMERIC:
> >> return this.numericPairParameterInput;
> >> default:
> >> return null;
> >> }
> >> }
> >
> >
> > What I'm facing there is that *this.parameterType* is always null and
> never
> > sees the value set to it in the Select component's event handler method !
> >
> > I understand there could be other ways to achieve the same behavior but
> why
> > isn't this behaving as I expect ?
> >
> > *---------------------*
> > *Muhammad Gelbana*
> > http://www.linkedin.com/in/mgelbana
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [t5.4-beta-6] Page class member variable scope

Posted by Geoff Callender <ge...@gmail.com>.
By returning "this" you're doing a page refresh, which is an HTTP 302 redirect, instead of an AJAX response.

The redirect causes the browser to issue a second request - a fresh page request - which will be freshly rendered by your stateless page class without any knowledge of the value you set in the previous request. You can see the 302 response and the second request with the browser's web inspector or firebug.

Here's a working example:

	http://jumpstart.doublenegative.com.au/jumpstart7/examples/ajax/select1

Cheers,

Geoff

On 12 Jul 2014, at 11:55 pm, Muhammad Gelbana <m....@gmail.com> wrote:

> I hope I selected a valid subject !
> 
> When I handle a VALUE_CHANGED event for a Select component. I receive the
> current value for the Select component as an event handler method parameter.
> 
> I use this parameter to set a member variable in the page's class.
> 
> @OnEvent(component = "parameterType", value = EventConstants.VALUE_CHANGED)
>> private Object pairParameterTypeChanged(ChariotTestTypePairParameterType
>> selectedType) {
>> this.parameterType = selectedType;
>> System.out.println("Type1: " + this.parameterType);
>> return this;
>> }
> 
> 
> In another part of the page, I use a Delegate to conditionally display a
> block.
> 
> public Block getPairParameterInputBlock() {
>> System.out.println("Type2: " + this.parameterType);
>> if (this.parameterType == null) {
>> return null;
>> }
>> switch (this.parameterType) {
>> case TEXT:
>> return this.textPairParameterInput;
>> case NUMERIC:
>> return this.numericPairParameterInput;
>> default:
>> return null;
>> }
>> }
> 
> 
> What I'm facing there is that *this.parameterType* is always null and never
> sees the value set to it in the Select component's event handler method !
> 
> I understand there could be other ways to achieve the same behavior but why
> isn't this behaving as I expect ?
> 
> *---------------------*
> *Muhammad Gelbana*
> http://www.linkedin.com/in/mgelbana


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