You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Chang <da...@yahoo.com> on 2010/03/21 05:31:47 UTC

Ajax has too much control?

Forgive me about this meaningless subject, but I cannot think of a better one.

I have been learning Wicket through the WIA book. I just found out something interesting to me. Not sure it is a bug, design, or something I did wrong.

I have a page with three Wicket elements:

1. Locale selector through a DropDownChoice list. WIA has complete code about how this works and I copied the solution into this page

2. Country DropDownChoice, whose values change between English and Chinese depending on Locale DDC. 

3. State DropDownChoice, whose values change between English and Chinese depending on Locale DDC. The values in this DDC depends on the chosen value in Country DDC.

Here are the experiments

Experiment#1.

Country DDC does not control values in State DDC via Ajax and it has 

protected boolean wantOnSelectionChangedNotifications() {
  return true;
}

Everything works like a charm, which means 

(1) when Country DDC value changes, State DDC changes accodingly.
(2) when Locale changes, both Country DDC and State DDC lists change display values accordingly (which means both DDCs show a list of values in the same language).

Experiment#2.

Country DDC controls values in State DDC via Ajax. In this case, when page is first loaded, I do not touch the Country DDC or State DDC. I simply change locale value any number of times, both Country DDC and State DDC lists change correctly depending on the session locale. Here is the strange thing. Then I change Country DDC value, State DDC changes correctly. Since then, HOWEVER, if I change locale values, ONLY Country DDC list changes correctly; State DDC list is not updated. It seems Wicket decides that State DDC is forever Aja-controlled by Country DDC only.

Not qure sure if this a bug, design, or I did something wrong.

Please let me if you have difficulty understanding the experiments.

Thanks for any info or help.

Cheers!



      

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


Re: Ajax has too much control?

Posted by Johan Compagner <jc...@gmail.com>.
Do you add the state ddc to the ajax target when you get a ajax country event?
----- Original message -----
>
> Sven,
>
> Thanks for your input. It seems that you do not understand the problem I have
> (Wicket problem??? or my page problem???). I know how Ajax works by adding
> components to Ajax request target.
>
> When it is non-Ajax, my page runs correctly with all three controls. When
> Country DDC Ajax-controls State DDC, the two DDC works correctly. The problem is
> that once this Ajax control is triggered by selecting a value in Country DDC,
> the State DDC list is NOT updated when the Locale DDC value is changed.
>
> I have a feel that Wicket has a problem here. I am using Wicket 1.4.7.
>
> Regards.
> -David
>
>
>
> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net> wrote:
>
> > From: Sven Meier <sv...@meiers.net>
> > Subject: Re: Ajax has too much control?
> > To: users@wicket.apache.org
> > Date: Sunday, March 21, 2010, 7:25 AM
> > Hi David,
> >
> > DropDownChoice#wantOnSelectionChangedNotifications() will
> > trigger
> > rendering of the complete page.
> > On Ajax request only those components are rendered you
> > explicitely 'add'
> > to the request, see AjaxRequestTarget#addComponent().
> >
> > If you want to have the same for Ajax requests, you can
> > just 'add' the
> > complete page.
> >
> > This is not very efficient though.
> >
> > Sven
> >
> > David Chang wrote:
> > > Forgive me about this meaningless subject, but I
> > cannot think of a better one.
> > >
> > > I have been learning Wicket through the WIA book. I
> > just found out something interesting to me. Not sure it is a
> > bug, design, or something I did wrong.
> > >
> > > I have a page with three Wicket elements:
> > >
> > > 1. Locale selector through a DropDownChoice list. WIA
> > has complete code about how this works and I copied the
> > solution into this page
> > >
> > > 2. Country DropDownChoice, whose values change between
> > English and Chinese depending on Locale DDC.
> > >
> > > 3. State DropDownChoice, whose values change between
> > English and Chinese depending on Locale DDC. The values in
> > this DDC depends on the chosen value in Country DDC.
> > >
> > > Here are the experiments
> > >
> > > Experiment#1.
> > >
> > > Country DDC does not control values in State DDC via
> > Ajax and it has
> > >
> > > protected boolean
> > wantOnSelectionChangedNotifications() {
> > >    return true;
> > > }
> > >
> > > Everything works like a charm, which means
> > >
> > > (1) when Country DDC value changes, State DDC changes
> > accodingly.
> > > (2) when Locale changes, both Country DDC and State
> > DDC lists change display values accordingly (which means
> > both DDCs show a list of values in the same language).
> > >
> > > Experiment#2.
> > >
> > > Country DDC controls values in State DDC via Ajax. In
> > this case, when page is first loaded, I do not touch the
> > Country DDC or State DDC. I simply change locale value any
> > number of times, both Country DDC and State DDC lists change
> > correctly depending on the session locale. Here is the
> > strange thing. Then I change Country DDC value, State DDC
> > changes correctly. Since then, HOWEVER, if I change locale
> > values, ONLY Country DDC list changes correctly; State DDC
> > list is not updated. It seems Wicket decides that State DDC
> > is forever Aja-controlled by Country DDC only.
> > >
> > > Not qure sure if this a bug, design, or I did
> > something wrong.
> > >
> > > Please let me if you have difficulty understanding the
> > experiments.
> > >
> > > Thanks for any info or help.
> > >
> > > Cheers!
> > >
> > >
> > >
> > >        
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> > >    
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
>           
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


RE: Customizable PageParameters class?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Thanks for that. Unfortunately it looks like the IPageFactory is already
provided with a PageProperties object. I might have to go back a level
and see what is invoking the IPageFactory as that is likely to be where
PageProperties is created.

I can't really do 'pre processing' of the data because I don't know what
the types of each parameter across the application is at that point.

What I'm aiming to try and do is override the 'getLong' method so that I
can trim off any 'jsession junk' that some search engines append to the
parameters when they store links to the website. They cause havoc at a
later date, especially the ones that encode the ';'. The url sent to the
app is then:

/a/34/b/23;jessionid=blah

When I call pageParameters.getLong("b", -1) it tries to interpret 

23;jessionid=blah

As the integer value of parameter "b" - which has obvious consequences.

I thought I could override getLong in my own PageParameters class and
trim off any trailing non digit characters before doing the conversion.

> -----Original Message-----
> From: Mauro Ciancio [mailto:maurociancio@gmail.com]
> Sent: Tuesday, 30 March 2010 12:33 PM
> To: users@wicket.apache.org
> Subject: Re: Customizable PageParameters class?
> 
> Chris:
> 
> On Mon, Mar 29, 2010 at 10:22 PM, Chris Colman
> <ch...@stepaheadsoftware.com> wrote:
> > I wanted to add some error processing to some of the parameters I
> > receive and the processing is 'generic' for any integer types.
> >
> > The easiest way to do this would be in a derivative of the
> > PageParameters class. Given that wicket has lots of plug ins
facilities
> > and customizing options I was wondering if it's possible to specify
a
> > PageParameters factory to provide objects that wicket should use
when
> > processing a request.
> >
> > Does such a beasty exist?
> 
> You can intercept the page creation and parse the page parameters
> and validate it if needed. Take a look at:
> 
> Application#getSessionSettings()
> ISessionSettings#setPageFactory()
> IPageFactory interface.
> 
> HTH.
> Cheers.
> --
> Mauro Ciancio <maurociancio at gmail dot com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


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


Re: Customizable PageParameters class?

Posted by Mauro Ciancio <ma...@gmail.com>.
Chris:

On Mon, Mar 29, 2010 at 10:22 PM, Chris Colman
<ch...@stepaheadsoftware.com> wrote:
> I wanted to add some error processing to some of the parameters I
> receive and the processing is 'generic' for any integer types.
>
> The easiest way to do this would be in a derivative of the
> PageParameters class. Given that wicket has lots of plug ins facilities
> and customizing options I was wondering if it's possible to specify a
> PageParameters factory to provide objects that wicket should use when
> processing a request.
>
> Does such a beasty exist?

You can intercept the page creation and parse the page parameters
and validate it if needed. Take a look at:

Application#getSessionSettings()
ISessionSettings#setPageFactory()
IPageFactory interface.

HTH.
Cheers.
-- 
Mauro Ciancio <maurociancio at gmail dot com>

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


Customizable PageParameters class?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
I wanted to add some error processing to some of the parameters I
receive and the processing is 'generic' for any integer types.

The easiest way to do this would be in a derivative of the
PageParameters class. Given that wicket has lots of plug ins facilities
and customizing options I was wondering if it's possible to specify a
PageParameters factory to provide objects that wicket should use when
processing a request.

Does such a beasty exist?



> -----Original Message-----
> From: Sven Meier [mailto:sven@meiers.net]
> Sent: Monday, 22 March 2010 2:30 AM
> To: users@wicket.apache.org
> Subject: Re: Ajax has too much control?
> 
> David,
> 
>  >It seems that you do not understand the problem I have
> 
> obviously not ;).
> 
> A quickstart would help me to understand your problem better, but
> perhaps others have already a clue?
> 
> Sven
> 
> David Chang wrote:
> > Sven,
> >
> > Thanks for your input. It seems that you do not understand the
problem I
> have (Wicket problem??? or my page problem???). I know how Ajax works
by
> adding components to Ajax request target.
> >
> > When it is non-Ajax, my page runs correctly with all three controls.
> When Country DDC Ajax-controls State DDC, the two DDC works correctly.
The
> problem is that once this Ajax control is triggered by selecting a
value
> in Country DDC, the State DDC list is NOT updated when the Locale DDC
> value is changed.
> >
> > I have a feel that Wicket has a problem here. I am using Wicket
1.4.7.
> >
> > Regards.
> > -David
> >
> >
> >
> > --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net> wrote:
> >
> >
> >> From: Sven Meier <sv...@meiers.net>
> >> Subject: Re: Ajax has too much control?
> >> To: users@wicket.apache.org
> >> Date: Sunday, March 21, 2010, 7:25 AM
> >> Hi David,
> >>
> >> DropDownChoice#wantOnSelectionChangedNotifications() will
> >> trigger
> >> rendering of the complete page.
> >> On Ajax request only those components are rendered you
> >> explicitely 'add'
> >> to the request, see AjaxRequestTarget#addComponent().
> >>
> >> If you want to have the same for Ajax requests, you can
> >> just 'add' the
> >> complete page.
> >>
> >> This is not very efficient though.
> >>
> >> Sven
> >>
> >> David Chang wrote:
> >>
> >>> Forgive me about this meaningless subject, but I
> >>>
> >> cannot think of a better one.
> >>
> >>> I have been learning Wicket through the WIA book. I
> >>>
> >> just found out something interesting to me. Not sure it is a
> >> bug, design, or something I did wrong.
> >>
> >>> I have a page with three Wicket elements:
> >>>
> >>> 1. Locale selector through a DropDownChoice list. WIA
> >>>
> >> has complete code about how this works and I copied the
> >> solution into this page
> >>
> >>> 2. Country DropDownChoice, whose values change between
> >>>
> >> English and Chinese depending on Locale DDC.
> >>
> >>> 3. State DropDownChoice, whose values change between
> >>>
> >> English and Chinese depending on Locale DDC. The values in
> >> this DDC depends on the chosen value in Country DDC.
> >>
> >>> Here are the experiments
> >>>
> >>> Experiment#1.
> >>>
> >>> Country DDC does not control values in State DDC via
> >>>
> >> Ajax and it has
> >>
> >>> protected boolean
> >>>
> >> wantOnSelectionChangedNotifications() {
> >>
> >>>    return true;
> >>> }
> >>>
> >>> Everything works like a charm, which means
> >>>
> >>> (1) when Country DDC value changes, State DDC changes
> >>>
> >> accodingly.
> >>
> >>> (2) when Locale changes, both Country DDC and State
> >>>
> >> DDC lists change display values accordingly (which means
> >> both DDCs show a list of values in the same language).
> >>
> >>> Experiment#2.
> >>>
> >>> Country DDC controls values in State DDC via Ajax. In
> >>>
> >> this case, when page is first loaded, I do not touch the
> >> Country DDC or State DDC. I simply change locale value any
> >> number of times, both Country DDC and State DDC lists change
> >> correctly depending on the session locale. Here is the
> >> strange thing. Then I change Country DDC value, State DDC
> >> changes correctly. Since then, HOWEVER, if I change locale
> >> values, ONLY Country DDC list changes correctly; State DDC
> >> list is not updated. It seems Wicket decides that State DDC
> >> is forever Aja-controlled by Country DDC only.
> >>
> >>> Not qure sure if this a bug, design, or I did
> >>>
> >> something wrong.
> >>
> >>> Please let me if you have difficulty understanding the
> >>>
> >> experiments.
> >>
> >>> Thanks for any info or help.
> >>>
> >>> Cheers!
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
---------------------------------------------------------------------
> >>
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>>
> >>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >>
> >
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


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


Re: Ajax has too much control?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Hi!

> I tried your approach it will not be working for me. Because I am going to add other required fields before or after the two dropdown list. Using AjaxFormSubmitBehavior would likely cause validation errors all the time.

No. AjaxFormSubmittingChangeListenerBehavior does NOT validate the
form. That is the whole point of the behavior.

**
Martin

>
> All the best,
> David
>
> --- On Mon, 3/22/10, Martin Makundi <ma...@koodaripalvelut.com> wrote:
>
>> From: Martin Makundi <ma...@koodaripalvelut.com>
>> Subject: Re: Ajax has too much control?
>> To: users@wicket.apache.org
>> Date: Monday, March 22, 2010, 10:52 AM
>> Hi!
>>
>> If you redraw something, you need to submit the form
>> values, otherwise
>> the redrawn state is different... if that's your case.
>>
>> **
>> Martin
>>
>> 2010/3/22 David Chang <da...@yahoo.com>:
>> >
>> > Hello Martin,
>> >
>> > Thanks for your input and sharing your code! I will
>> give it a try.
>> >
>> > Did you have the same problem I have now?
>> >
>> > Here is what I have for the Country DDC:
>> >
>> > countryDDC.add(new
>> AjaxFormComponentUpdatingBehavior("onchange") {
>> > @Override
>> >    protected void onUpdate(AjaxRequestTarget target)
>> {
>> >        if (target != null) {
>> >        MyUser u = form.getModelObject();
>> >        u.setState(null);
>> >        DropDownChoice stateDDC = (DropDownChoice)
>> form.get("state");
>> >
>>  stateDDC.setChoices(objectService.findStatesForLocale(getSession().getLocale()));
>> >        target.addComponent(countryDDC);
>> >        target.addComponent(stateDDC);
>> >        }
>> >    }
>> > });
>> >
>> >
>> > As you can see, I am using
>> AjaxFormComponentUpdatingBehavior. Why do you use
>> AjaxFormSubmitBehavior? In my case, I am not submitting a
>> form.
>> >
>> > I am new in Wicket. Thanks for your help!
>> >
>> > Best.
>> > -David
>> >
>> >
>> >
>> >
>> >
>> > --- On Sun, 3/21/10, Martin Makundi <ma...@koodaripalvelut.com>
>> wrote:
>> >
>> >> From: Martin Makundi <ma...@koodaripalvelut.com>
>> >> Subject: Re: Ajax has too much control?
>> >> To: users@wicket.apache.org
>> >> Date: Sunday, March 21, 2010, 11:38 AM
>> >> Hi David!
>> >>
>> >> Maybe you need this (at least this is what worked
>> for me):
>> >>
>> >> /**
>> >>  * @author Martin
>> >>  */
>> >> public abstract class
>> >> AjaxFormSubmittingChangeListenerBehavior extends
>> >>     AjaxFormSubmitBehavior {
>> >>   private final static Method hiddenFieldGetter;
>> >>   static {
>> >>     try {
>> >>       hiddenFieldGetter =
>> >> Form.class.getDeclaredMethod("getHiddenFieldId");
>> >>
>> >> hiddenFieldGetter.setAccessible(true);
>> >>     } catch (Exception e) {
>> >>       throw new RuntimeException(e);
>> >>     }
>> >>   }
>> >>
>> >>   /**
>> >>    * @see
>> >>
>> org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
>> >>    */
>> >>   @Override
>> >>   protected void onBind() {
>> >>     super.onBind();
>> >>
>> >>     if (!(getComponent() instanceof
>> >> IOnChangeListener))
>> >>     {
>> >>       throw new
>> >> WicketRuntimeException("Behavior " +
>> getClass().getName() +
>> >>         " can only be added to an
>> >> instance of a IOnChangeListener");
>> >>     }
>> >>   }
>> >>
>> >>   /**
>> >>    * @param event
>> >>    */
>> >>   public
>> >> AjaxFormSubmittingChangeListenerBehavior(String
>> event) {
>> >>     super(event);
>> >>   }
>> >>
>> >>   /**
>> >>    * @see
>> >>
>> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
>> >>    */
>> >>   @Override
>> >>   protected void onError(AjaxRequestTarget
>> target) {
>> >>     onSubmit(target);
>> >>   }
>> >>
>> >>   /**
>> >>    * @see
>> >>
>> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
>> >>    */
>> >>   @Override
>> >>   protected void onEvent(AjaxRequestTarget
>> target) {
>> >>     HttpServletRequest httpServletRequest =
>> >> ((WebRequest) getComponent()
>> >>
>> >> .getRequest()).getHttpServletRequest();
>> >>
>> >>     Map parameters;
>> >>
>> >>     if (httpServletRequest instanceof
>> >> MockHttpServletRequest) {
>> >>       parameters =
>> >> ((MockHttpServletRequest)
>> >> httpServletRequest).getParameterMap();
>> >>     } else {
>> >>       parameters =
>> >> ((org.mortbay.jetty.Request)
>> >> httpServletRequest).getParameters();
>> >>     }
>> >>
>> >>     parameters.put(getHiddenFieldId(getForm()),
>> >>
>> getComponent().urlFor(IOnChangeListener.INTERFACE));
>> >>
>> >>     final FormComponent<?> formComponent
>> =
>> >> (FormComponent<?>) getComponent();
>> >>
>> >>     try {
>> >>       if (isUpdateModel()) {
>> >>         formComponent.inputChanged();
>> >>         formComponent.validate();
>> >>
>> >>         if
>> >> (!formComponent.hasErrorMessage()) {
>> >>           formComponent.valid();
>> >>
>> >> formComponent.updateModel();
>> >>         }
>> >>       }
>> >>
>> >>       super.onEvent(target);
>> >>     } catch (RuntimeException e) {
>> >>
>> >>
>> Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class,
>> >> e);
>> >>       onError(target);
>> >>     }
>> >>   }
>> >>
>> >>   /**
>> >>    * @return boolean
>> >>    */
>> >>   protected boolean isUpdateModel() {
>> >>     return true;
>> >>   }
>> >>
>> >>   /**
>> >>    * @param form
>> >>    * @return String
>> >>    */
>> >>   private String getHiddenFieldId(Form<?>
>> form)
>> >> {
>> >>     try {
>> >>       Form<?> root =
>> >> form.getRootForm();
>> >>       return (String)
>> >> hiddenFieldGetter.invoke(root);
>> >>     } catch (Exception e) {
>> >>       throw new RuntimeException(e);
>> >>     }
>> >>   }
>> >> }
>> >>
>> >>
>> >> public abstract class
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice<T>
>> >> extends
>> >> DropDownChoice<T> {
>> >>   /** Initialize */ {
>> >>     add(new
>> >>
>> AjaxFormSubmittingChangeListenerBehavior(JavaScriptConstants.ONCHANGE)
>> >> {
>> >>       @Override
>> >>       protected void
>> >> onSubmit(AjaxRequestTarget target) {
>> >>
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice.this.onSubmit(target);
>> >>       }
>> >>     });
>> >>   }
>> >>
>> >>   /**
>> >>    * @see
>> >> org.apache.wicket.MarkupContainer#toString()
>> >>    */
>> >>   @Override
>> >>   public String toString() {
>> >>     return super.toString() + " Value: " +
>> >> getValue();
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param choices
>> >>    * @param renderer
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >>       IModel<List<? extends T>>
>> >> choices, IChoiceRenderer<T> renderer) {
>> >>     super(id, choices, renderer);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param target
>> >>    */
>> >>   protected abstract void
>> onSubmit(AjaxRequestTarget
>> >> target);
>> >>
>> >>   /**
>> >>    * @param target
>> >>    */
>> >>   protected void onError(AjaxRequestTarget
>> target) {
>> >>     onSubmit(target);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param choices
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >>       IModel<List<? extends T>>
>> >> choices) {
>> >>     super(id, choices);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param model
>> >>    * @param choices
>> >>    * @param renderer
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> IModel<T> model,
>> >>       IModel<List<? extends T>>
>> >> choices, IChoiceRenderer<T> renderer) {
>> >>     super(id, model, choices, renderer);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param model
>> >>    * @param choices
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> IModel<T> model,
>> >>       IModel<List<? extends T>>
>> >> choices) {
>> >>     super(id, model, choices);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param model
>> >>    * @param data
>> >>    * @param renderer
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> IModel<T> model,
>> >>       List<? extends T> data,
>> >> IChoiceRenderer<T> renderer) {
>> >>     super(id, model, data, renderer);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param model
>> >>    * @param choices
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> IModel<T> model,
>> >>       List<? extends T> choices) {
>> >>     super(id, model, choices);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param data
>> >>    * @param renderer
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> List<? extends T> data,
>> >>       IChoiceRenderer<T> renderer) {
>> >>     super(id, data, renderer);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    * @param choices
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> >> List<? extends T> choices) {
>> >>     super(id, choices);
>> >>   }
>> >>
>> >>   /**
>> >>    * @param id
>> >>    */
>> >>   public
>> >>
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id) {
>> >>     super(id);
>> >>   }
>> >> }
>> >>
>> >>
>> >> **
>> >> Martin
>> >> 2010/3/21 Sven Meier <sv...@meiers.net>:
>> >> > David,
>> >> >
>> >> >>It seems that you do not understand the
>> problem I
>> >> have
>> >> >
>> >> > obviously not ;).
>> >> >
>> >> > A quickstart would help me to understand your
>> problem
>> >> better, but perhaps
>> >> > others have already a clue?
>> >> >
>> >> > Sven
>> >> >
>> >> > David Chang wrote:
>> >> >>
>> >> >> Sven,
>> >> >>
>> >> >> Thanks for your input. It seems that you
>> do not
>> >> understand the problem I
>> >> >> have (Wicket problem??? or my page
>> problem???). I
>> >> know how Ajax works by
>> >> >> adding components to Ajax request
>> target.
>> >> >>
>> >> >> When it is non-Ajax, my page runs
>> correctly with
>> >> all three controls. When
>> >> >> Country DDC Ajax-controls State DDC, the
>> two DDC
>> >> works correctly. The
>> >> >> problem is that once this Ajax control
>> is
>> >> triggered by selecting a value in
>> >> >> Country DDC, the State DDC list is NOT
>> updated
>> >> when the Locale DDC value is
>> >> >> changed.
>> >> >>
>> >> >> I have a feel that Wicket has a problem
>> here. I am
>> >> using Wicket 1.4.7.
>> >> >>
>> >> >> Regards.
>> >> >> -David
>> >> >>
>> >> >>
>> >> >>
>> >> >> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net>
>> >> wrote:
>> >> >>
>> >> >>
>> >> >>>
>> >> >>> From: Sven Meier <sv...@meiers.net>
>> >> >>> Subject: Re: Ajax has too much
>> control?
>> >> >>> To: users@wicket.apache.org
>> >> >>> Date: Sunday, March 21, 2010, 7:25
>> AM
>> >> >>> Hi David,
>> >> >>>
>> >> >>>
>> >>
>> DropDownChoice#wantOnSelectionChangedNotifications() will
>> >> >>> trigger rendering of the complete
>> page.
>> >> >>> On Ajax request only those components
>> are
>> >> rendered you
>> >> >>> explicitely 'add' to the request,
>> see
>> >> AjaxRequestTarget#addComponent().
>> >> >>>
>> >> >>> If you want to have the same for
>> Ajax
>> >> requests, you can
>> >> >>> just 'add' the complete page.
>> >> >>>
>> >> >>> This is not very efficient though.
>> >> >>>
>> >> >>> Sven
>> >> >>>
>> >> >>> David Chang wrote:
>> >> >>>
>> >> >>>>
>> >> >>>> Forgive me about this meaningless
>> subject,
>> >> but I
>> >> >>>>
>> >> >>>
>> >> >>> cannot think of a better one.
>> >> >>>
>> >> >>>>
>> >> >>>> I have been learning Wicket
>> through the
>> >> WIA book. I
>> >> >>>>
>> >> >>>
>> >> >>> just found out something interesting
>> to me.
>> >> Not sure it is a
>> >> >>> bug, design, or something I did
>> wrong.
>> >> >>>
>> >> >>>>
>> >> >>>> I have a page with three Wicket
>> elements:
>> >> >>>>
>> >> >>>> 1. Locale selector through a
>> >> DropDownChoice list. WIA
>> >> >>>>
>> >> >>>
>> >> >>> has complete code about how this
>> works and I
>> >> copied the
>> >> >>> solution into this page
>> >> >>>
>> >> >>>>
>> >> >>>> 2. Country DropDownChoice, whose
>> values
>> >> change between
>> >> >>>>
>> >> >>>
>> >> >>> English and Chinese depending on
>> Locale DDC.
>> >> >>>>
>> >> >>>> 3. State DropDownChoice, whose
>> values
>> >> change between
>> >> >>>>
>> >> >>>
>> >> >>> English and Chinese depending on
>> Locale DDC.
>> >> The values in
>> >> >>> this DDC depends on the chosen value
>> in
>> >> Country DDC.
>> >> >>>
>> >> >>>>
>> >> >>>> Here are the experiments
>> >> >>>>
>> >> >>>> Experiment#1.
>> >> >>>>
>> >> >>>> Country DDC does not control
>> values in
>> >> State DDC via
>> >> >>>>
>> >> >>>
>> >> >>> Ajax and it has
>> >> >>>>
>> >> >>>> protected boolean
>> >> >>>>
>> >> >>>
>> >> >>> wantOnSelectionChangedNotifications()
>> {
>> >> >>>
>> >> >>>>
>> >> >>>>   return true;
>> >> >>>> }
>> >> >>>>
>> >> >>>> Everything works like a charm,
>> which
>> >> means
>> >> >>>> (1) when Country DDC value
>> changes, State
>> >> DDC changes
>> >> >>>>
>> >> >>>
>> >> >>> accodingly.
>> >> >>>
>> >> >>>>
>> >> >>>> (2) when Locale changes, both
>> Country DDC
>> >> and State
>> >> >>>>
>> >> >>>
>> >> >>> DDC lists change display values
>> accordingly
>> >> (which means
>> >> >>> both DDCs show a list of values in
>> the same
>> >> language).
>> >> >>>
>> >> >>>>
>> >> >>>> Experiment#2.
>> >> >>>>
>> >> >>>> Country DDC controls values in
>> State DDC
>> >> via Ajax. In
>> >> >>>>
>> >> >>>
>> >> >>> this case, when page is first loaded,
>> I do not
>> >> touch the
>> >> >>> Country DDC or State DDC. I simply
>> change
>> >> locale value any
>> >> >>> number of times, both Country DDC and
>> State
>> >> DDC lists change
>> >> >>> correctly depending on the session
>> locale.
>> >> Here is the
>> >> >>> strange thing. Then I change Country
>> DDC
>> >> value, State DDC
>> >> >>> changes correctly. Since then,
>> HOWEVER, if I
>> >> change locale
>> >> >>> values, ONLY Country DDC list
>> changes
>> >> correctly; State DDC
>> >> >>> list is not updated. It seems Wicket
>> decides
>> >> that State DDC
>> >> >>> is forever Aja-controlled by Country
>> DDC
>> >> only.
>> >> >>>
>> >> >>>>
>> >> >>>> Not qure sure if this a bug,
>> design, or I
>> >> did
>> >> >>>>
>> >> >>>
>> >> >>> something wrong.
>> >> >>>
>> >> >>>>
>> >> >>>> Please let me if you have
>> difficulty
>> >> understanding the
>> >> >>>>
>> >> >>>
>> >> >>> experiments.
>> >> >>>
>> >> >>>>
>> >> >>>> Thanks for any info or help.
>> >> >>>>
>> >> >>>> Cheers!
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>
>> >> >>>
>> >>
>> ---------------------------------------------------------------------
>> >> >>>
>> >> >>>>
>> >> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> >>>> For additional commands, e-mail:
>> users-help@wicket.apache.org
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>
>> >> >>>
>> >>
>> ---------------------------------------------------------------------
>> >> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> >>> For additional commands, e-mail: users-help@wicket.apache.org
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >>
>> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >>
>> ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> > For additional commands, e-mail: users-help@wicket.apache.org
>> >> >
>> >> >
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Ajax has too much control?

Posted by David Chang <da...@yahoo.com>.
Martin, 

I tried your approach it will not be working for me. Because I am going to add other required fields before or after the two dropdown list. Using AjaxFormSubmitBehavior would likely cause validation errors all the time. 

Besides, AjaxFormComponentUpdatingBehavior should be what I need: redraw part of a web page via Ajax without submitting a form.


Thank YOU for your help!

All the best,
David

--- On Mon, 3/22/10, Martin Makundi <ma...@koodaripalvelut.com> wrote:

> From: Martin Makundi <ma...@koodaripalvelut.com>
> Subject: Re: Ajax has too much control?
> To: users@wicket.apache.org
> Date: Monday, March 22, 2010, 10:52 AM
> Hi!
> 
> If you redraw something, you need to submit the form
> values, otherwise
> the redrawn state is different... if that's your case.
> 
> **
> Martin
> 
> 2010/3/22 David Chang <da...@yahoo.com>:
> >
> > Hello Martin,
> >
> > Thanks for your input and sharing your code! I will
> give it a try.
> >
> > Did you have the same problem I have now?
> >
> > Here is what I have for the Country DDC:
> >
> > countryDDC.add(new
> AjaxFormComponentUpdatingBehavior("onchange") {
> > @Override
> >    protected void onUpdate(AjaxRequestTarget target)
> {
> >        if (target != null) {
> >        MyUser u = form.getModelObject();
> >        u.setState(null);
> >        DropDownChoice stateDDC = (DropDownChoice)
> form.get("state");
> >      
>  stateDDC.setChoices(objectService.findStatesForLocale(getSession().getLocale()));
> >        target.addComponent(countryDDC);
> >        target.addComponent(stateDDC);
> >        }
> >    }
> > });
> >
> >
> > As you can see, I am using
> AjaxFormComponentUpdatingBehavior. Why do you use
> AjaxFormSubmitBehavior? In my case, I am not submitting a
> form.
> >
> > I am new in Wicket. Thanks for your help!
> >
> > Best.
> > -David
> >
> >
> >
> >
> >
> > --- On Sun, 3/21/10, Martin Makundi <ma...@koodaripalvelut.com>
> wrote:
> >
> >> From: Martin Makundi <ma...@koodaripalvelut.com>
> >> Subject: Re: Ajax has too much control?
> >> To: users@wicket.apache.org
> >> Date: Sunday, March 21, 2010, 11:38 AM
> >> Hi David!
> >>
> >> Maybe you need this (at least this is what worked
> for me):
> >>
> >> /**
> >>  * @author Martin
> >>  */
> >> public abstract class
> >> AjaxFormSubmittingChangeListenerBehavior extends
> >>     AjaxFormSubmitBehavior {
> >>   private final static Method hiddenFieldGetter;
> >>   static {
> >>     try {
> >>       hiddenFieldGetter =
> >> Form.class.getDeclaredMethod("getHiddenFieldId");
> >>
> >> hiddenFieldGetter.setAccessible(true);
> >>     } catch (Exception e) {
> >>       throw new RuntimeException(e);
> >>     }
> >>   }
> >>
> >>   /**
> >>    * @see
> >>
> org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
> >>    */
> >>   @Override
> >>   protected void onBind() {
> >>     super.onBind();
> >>
> >>     if (!(getComponent() instanceof
> >> IOnChangeListener))
> >>     {
> >>       throw new
> >> WicketRuntimeException("Behavior " +
> getClass().getName() +
> >>         " can only be added to an
> >> instance of a IOnChangeListener");
> >>     }
> >>   }
> >>
> >>   /**
> >>    * @param event
> >>    */
> >>   public
> >> AjaxFormSubmittingChangeListenerBehavior(String
> event) {
> >>     super(event);
> >>   }
> >>
> >>   /**
> >>    * @see
> >>
> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
> >>    */
> >>   @Override
> >>   protected void onError(AjaxRequestTarget
> target) {
> >>     onSubmit(target);
> >>   }
> >>
> >>   /**
> >>    * @see
> >>
> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
> >>    */
> >>   @Override
> >>   protected void onEvent(AjaxRequestTarget
> target) {
> >>     HttpServletRequest httpServletRequest =
> >> ((WebRequest) getComponent()
> >>
> >> .getRequest()).getHttpServletRequest();
> >>
> >>     Map parameters;
> >>
> >>     if (httpServletRequest instanceof
> >> MockHttpServletRequest) {
> >>       parameters =
> >> ((MockHttpServletRequest)
> >> httpServletRequest).getParameterMap();
> >>     } else {
> >>       parameters =
> >> ((org.mortbay.jetty.Request)
> >> httpServletRequest).getParameters();
> >>     }
> >>
> >>     parameters.put(getHiddenFieldId(getForm()),
> >>
> getComponent().urlFor(IOnChangeListener.INTERFACE));
> >>
> >>     final FormComponent<?> formComponent
> =
> >> (FormComponent<?>) getComponent();
> >>
> >>     try {
> >>       if (isUpdateModel()) {
> >>         formComponent.inputChanged();
> >>         formComponent.validate();
> >>
> >>         if
> >> (!formComponent.hasErrorMessage()) {
> >>           formComponent.valid();
> >>
> >> formComponent.updateModel();
> >>         }
> >>       }
> >>
> >>       super.onEvent(target);
> >>     } catch (RuntimeException e) {
> >>
> >>
> Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class,
> >> e);
> >>       onError(target);
> >>     }
> >>   }
> >>
> >>   /**
> >>    * @return boolean
> >>    */
> >>   protected boolean isUpdateModel() {
> >>     return true;
> >>   }
> >>
> >>   /**
> >>    * @param form
> >>    * @return String
> >>    */
> >>   private String getHiddenFieldId(Form<?>
> form)
> >> {
> >>     try {
> >>       Form<?> root =
> >> form.getRootForm();
> >>       return (String)
> >> hiddenFieldGetter.invoke(root);
> >>     } catch (Exception e) {
> >>       throw new RuntimeException(e);
> >>     }
> >>   }
> >> }
> >>
> >>
> >> public abstract class
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice<T>
> >> extends
> >> DropDownChoice<T> {
> >>   /** Initialize */ {
> >>     add(new
> >>
> AjaxFormSubmittingChangeListenerBehavior(JavaScriptConstants.ONCHANGE)
> >> {
> >>       @Override
> >>       protected void
> >> onSubmit(AjaxRequestTarget target) {
> >>
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice.this.onSubmit(target);
> >>       }
> >>     });
> >>   }
> >>
> >>   /**
> >>    * @see
> >> org.apache.wicket.MarkupContainer#toString()
> >>    */
> >>   @Override
> >>   public String toString() {
> >>     return super.toString() + " Value: " +
> >> getValue();
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param choices
> >>    * @param renderer
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >>       IModel<List<? extends T>>
> >> choices, IChoiceRenderer<T> renderer) {
> >>     super(id, choices, renderer);
> >>   }
> >>
> >>   /**
> >>    * @param target
> >>    */
> >>   protected abstract void
> onSubmit(AjaxRequestTarget
> >> target);
> >>
> >>   /**
> >>    * @param target
> >>    */
> >>   protected void onError(AjaxRequestTarget
> target) {
> >>     onSubmit(target);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param choices
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >>       IModel<List<? extends T>>
> >> choices) {
> >>     super(id, choices);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param model
> >>    * @param choices
> >>    * @param renderer
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> IModel<T> model,
> >>       IModel<List<? extends T>>
> >> choices, IChoiceRenderer<T> renderer) {
> >>     super(id, model, choices, renderer);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param model
> >>    * @param choices
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> IModel<T> model,
> >>       IModel<List<? extends T>>
> >> choices) {
> >>     super(id, model, choices);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param model
> >>    * @param data
> >>    * @param renderer
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> IModel<T> model,
> >>       List<? extends T> data,
> >> IChoiceRenderer<T> renderer) {
> >>     super(id, model, data, renderer);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param model
> >>    * @param choices
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> IModel<T> model,
> >>       List<? extends T> choices) {
> >>     super(id, model, choices);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param data
> >>    * @param renderer
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> List<? extends T> data,
> >>       IChoiceRenderer<T> renderer) {
> >>     super(id, data, renderer);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    * @param choices
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> >> List<? extends T> choices) {
> >>     super(id, choices);
> >>   }
> >>
> >>   /**
> >>    * @param id
> >>    */
> >>   public
> >>
> AjaxFormSubmittingChangeListenerDropDownChoice(String id) {
> >>     super(id);
> >>   }
> >> }
> >>
> >>
> >> **
> >> Martin
> >> 2010/3/21 Sven Meier <sv...@meiers.net>:
> >> > David,
> >> >
> >> >>It seems that you do not understand the
> problem I
> >> have
> >> >
> >> > obviously not ;).
> >> >
> >> > A quickstart would help me to understand your
> problem
> >> better, but perhaps
> >> > others have already a clue?
> >> >
> >> > Sven
> >> >
> >> > David Chang wrote:
> >> >>
> >> >> Sven,
> >> >>
> >> >> Thanks for your input. It seems that you
> do not
> >> understand the problem I
> >> >> have (Wicket problem??? or my page
> problem???). I
> >> know how Ajax works by
> >> >> adding components to Ajax request
> target.
> >> >>
> >> >> When it is non-Ajax, my page runs
> correctly with
> >> all three controls. When
> >> >> Country DDC Ajax-controls State DDC, the
> two DDC
> >> works correctly. The
> >> >> problem is that once this Ajax control
> is
> >> triggered by selecting a value in
> >> >> Country DDC, the State DDC list is NOT
> updated
> >> when the Locale DDC value is
> >> >> changed.
> >> >>
> >> >> I have a feel that Wicket has a problem
> here. I am
> >> using Wicket 1.4.7.
> >> >>
> >> >> Regards.
> >> >> -David
> >> >>
> >> >>
> >> >>
> >> >> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net>
> >> wrote:
> >> >>
> >> >>
> >> >>>
> >> >>> From: Sven Meier <sv...@meiers.net>
> >> >>> Subject: Re: Ajax has too much
> control?
> >> >>> To: users@wicket.apache.org
> >> >>> Date: Sunday, March 21, 2010, 7:25
> AM
> >> >>> Hi David,
> >> >>>
> >> >>>
> >>
> DropDownChoice#wantOnSelectionChangedNotifications() will
> >> >>> trigger rendering of the complete
> page.
> >> >>> On Ajax request only those components
> are
> >> rendered you
> >> >>> explicitely 'add' to the request,
> see
> >> AjaxRequestTarget#addComponent().
> >> >>>
> >> >>> If you want to have the same for
> Ajax
> >> requests, you can
> >> >>> just 'add' the complete page.
> >> >>>
> >> >>> This is not very efficient though.
> >> >>>
> >> >>> Sven
> >> >>>
> >> >>> David Chang wrote:
> >> >>>
> >> >>>>
> >> >>>> Forgive me about this meaningless
> subject,
> >> but I
> >> >>>>
> >> >>>
> >> >>> cannot think of a better one.
> >> >>>
> >> >>>>
> >> >>>> I have been learning Wicket
> through the
> >> WIA book. I
> >> >>>>
> >> >>>
> >> >>> just found out something interesting
> to me.
> >> Not sure it is a
> >> >>> bug, design, or something I did
> wrong.
> >> >>>
> >> >>>>
> >> >>>> I have a page with three Wicket
> elements:
> >> >>>>
> >> >>>> 1. Locale selector through a
> >> DropDownChoice list. WIA
> >> >>>>
> >> >>>
> >> >>> has complete code about how this
> works and I
> >> copied the
> >> >>> solution into this page
> >> >>>
> >> >>>>
> >> >>>> 2. Country DropDownChoice, whose
> values
> >> change between
> >> >>>>
> >> >>>
> >> >>> English and Chinese depending on
> Locale DDC.
> >> >>>>
> >> >>>> 3. State DropDownChoice, whose
> values
> >> change between
> >> >>>>
> >> >>>
> >> >>> English and Chinese depending on
> Locale DDC.
> >> The values in
> >> >>> this DDC depends on the chosen value
> in
> >> Country DDC.
> >> >>>
> >> >>>>
> >> >>>> Here are the experiments
> >> >>>>
> >> >>>> Experiment#1.
> >> >>>>
> >> >>>> Country DDC does not control
> values in
> >> State DDC via
> >> >>>>
> >> >>>
> >> >>> Ajax and it has
> >> >>>>
> >> >>>> protected boolean
> >> >>>>
> >> >>>
> >> >>> wantOnSelectionChangedNotifications()
> {
> >> >>>
> >> >>>>
> >> >>>>   return true;
> >> >>>> }
> >> >>>>
> >> >>>> Everything works like a charm,
> which
> >> means
> >> >>>> (1) when Country DDC value
> changes, State
> >> DDC changes
> >> >>>>
> >> >>>
> >> >>> accodingly.
> >> >>>
> >> >>>>
> >> >>>> (2) when Locale changes, both
> Country DDC
> >> and State
> >> >>>>
> >> >>>
> >> >>> DDC lists change display values
> accordingly
> >> (which means
> >> >>> both DDCs show a list of values in
> the same
> >> language).
> >> >>>
> >> >>>>
> >> >>>> Experiment#2.
> >> >>>>
> >> >>>> Country DDC controls values in
> State DDC
> >> via Ajax. In
> >> >>>>
> >> >>>
> >> >>> this case, when page is first loaded,
> I do not
> >> touch the
> >> >>> Country DDC or State DDC. I simply
> change
> >> locale value any
> >> >>> number of times, both Country DDC and
> State
> >> DDC lists change
> >> >>> correctly depending on the session
> locale.
> >> Here is the
> >> >>> strange thing. Then I change Country
> DDC
> >> value, State DDC
> >> >>> changes correctly. Since then,
> HOWEVER, if I
> >> change locale
> >> >>> values, ONLY Country DDC list
> changes
> >> correctly; State DDC
> >> >>> list is not updated. It seems Wicket
> decides
> >> that State DDC
> >> >>> is forever Aja-controlled by Country
> DDC
> >> only.
> >> >>>
> >> >>>>
> >> >>>> Not qure sure if this a bug,
> design, or I
> >> did
> >> >>>>
> >> >>>
> >> >>> something wrong.
> >> >>>
> >> >>>>
> >> >>>> Please let me if you have
> difficulty
> >> understanding the
> >> >>>>
> >> >>>
> >> >>> experiments.
> >> >>>
> >> >>>>
> >> >>>> Thanks for any info or help.
> >> >>>>
> >> >>>> Cheers!
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>
> >> >>>
> >>
> ---------------------------------------------------------------------
> >> >>>
> >> >>>>
> >> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >>>> For additional commands, e-mail:
> users-help@wicket.apache.org
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>
> >> >>>
> >>
> ---------------------------------------------------------------------
> >> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >> >>>
> >> >>>
> >> >>>
> >> >>
> >> >>
> >> >>
> >> >>
> >>
> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >> For additional commands, e-mail: users-help@wicket.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> >
> >>
> ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> > For additional commands, e-mail: users-help@wicket.apache.org
> >> >
> >> >
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: Ajax has too much control?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Hi!

If you redraw something, you need to submit the form values, otherwise
the redrawn state is different... if that's your case.

**
Martin

2010/3/22 David Chang <da...@yahoo.com>:
>
> Hello Martin,
>
> Thanks for your input and sharing your code! I will give it a try.
>
> Did you have the same problem I have now?
>
> Here is what I have for the Country DDC:
>
> countryDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
> @Override
>    protected void onUpdate(AjaxRequestTarget target) {
>        if (target != null) {
>        MyUser u = form.getModelObject();
>        u.setState(null);
>        DropDownChoice stateDDC = (DropDownChoice) form.get("state");
>        stateDDC.setChoices(objectService.findStatesForLocale(getSession().getLocale()));
>        target.addComponent(countryDDC);
>        target.addComponent(stateDDC);
>        }
>    }
> });
>
>
> As you can see, I am using AjaxFormComponentUpdatingBehavior. Why do you use AjaxFormSubmitBehavior? In my case, I am not submitting a form.
>
> I am new in Wicket. Thanks for your help!
>
> Best.
> -David
>
>
>
>
>
> --- On Sun, 3/21/10, Martin Makundi <ma...@koodaripalvelut.com> wrote:
>
>> From: Martin Makundi <ma...@koodaripalvelut.com>
>> Subject: Re: Ajax has too much control?
>> To: users@wicket.apache.org
>> Date: Sunday, March 21, 2010, 11:38 AM
>> Hi David!
>>
>> Maybe you need this (at least this is what worked for me):
>>
>> /**
>>  * @author Martin
>>  */
>> public abstract class
>> AjaxFormSubmittingChangeListenerBehavior extends
>>     AjaxFormSubmitBehavior {
>>   private final static Method hiddenFieldGetter;
>>   static {
>>     try {
>>       hiddenFieldGetter =
>> Form.class.getDeclaredMethod("getHiddenFieldId");
>>
>> hiddenFieldGetter.setAccessible(true);
>>     } catch (Exception e) {
>>       throw new RuntimeException(e);
>>     }
>>   }
>>
>>   /**
>>    * @see
>> org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
>>    */
>>   @Override
>>   protected void onBind() {
>>     super.onBind();
>>
>>     if (!(getComponent() instanceof
>> IOnChangeListener))
>>     {
>>       throw new
>> WicketRuntimeException("Behavior " + getClass().getName() +
>>         " can only be added to an
>> instance of a IOnChangeListener");
>>     }
>>   }
>>
>>   /**
>>    * @param event
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerBehavior(String event) {
>>     super(event);
>>   }
>>
>>   /**
>>    * @see
>> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
>>    */
>>   @Override
>>   protected void onError(AjaxRequestTarget target) {
>>     onSubmit(target);
>>   }
>>
>>   /**
>>    * @see
>> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
>>    */
>>   @Override
>>   protected void onEvent(AjaxRequestTarget target) {
>>     HttpServletRequest httpServletRequest =
>> ((WebRequest) getComponent()
>>
>> .getRequest()).getHttpServletRequest();
>>
>>     Map parameters;
>>
>>     if (httpServletRequest instanceof
>> MockHttpServletRequest) {
>>       parameters =
>> ((MockHttpServletRequest)
>> httpServletRequest).getParameterMap();
>>     } else {
>>       parameters =
>> ((org.mortbay.jetty.Request)
>> httpServletRequest).getParameters();
>>     }
>>
>>     parameters.put(getHiddenFieldId(getForm()),
>> getComponent().urlFor(IOnChangeListener.INTERFACE));
>>
>>     final FormComponent<?> formComponent =
>> (FormComponent<?>) getComponent();
>>
>>     try {
>>       if (isUpdateModel()) {
>>         formComponent.inputChanged();
>>         formComponent.validate();
>>
>>         if
>> (!formComponent.hasErrorMessage()) {
>>           formComponent.valid();
>>
>> formComponent.updateModel();
>>         }
>>       }
>>
>>       super.onEvent(target);
>>     } catch (RuntimeException e) {
>>
>> Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class,
>> e);
>>       onError(target);
>>     }
>>   }
>>
>>   /**
>>    * @return boolean
>>    */
>>   protected boolean isUpdateModel() {
>>     return true;
>>   }
>>
>>   /**
>>    * @param form
>>    * @return String
>>    */
>>   private String getHiddenFieldId(Form<?> form)
>> {
>>     try {
>>       Form<?> root =
>> form.getRootForm();
>>       return (String)
>> hiddenFieldGetter.invoke(root);
>>     } catch (Exception e) {
>>       throw new RuntimeException(e);
>>     }
>>   }
>> }
>>
>>
>> public abstract class
>> AjaxFormSubmittingChangeListenerDropDownChoice<T>
>> extends
>> DropDownChoice<T> {
>>   /** Initialize */ {
>>     add(new
>> AjaxFormSubmittingChangeListenerBehavior(JavaScriptConstants.ONCHANGE)
>> {
>>       @Override
>>       protected void
>> onSubmit(AjaxRequestTarget target) {
>>
>> AjaxFormSubmittingChangeListenerDropDownChoice.this.onSubmit(target);
>>       }
>>     });
>>   }
>>
>>   /**
>>    * @see
>> org.apache.wicket.MarkupContainer#toString()
>>    */
>>   @Override
>>   public String toString() {
>>     return super.toString() + " Value: " +
>> getValue();
>>   }
>>
>>   /**
>>    * @param id
>>    * @param choices
>>    * @param renderer
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>>       IModel<List<? extends T>>
>> choices, IChoiceRenderer<T> renderer) {
>>     super(id, choices, renderer);
>>   }
>>
>>   /**
>>    * @param target
>>    */
>>   protected abstract void onSubmit(AjaxRequestTarget
>> target);
>>
>>   /**
>>    * @param target
>>    */
>>   protected void onError(AjaxRequestTarget target) {
>>     onSubmit(target);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param choices
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>>       IModel<List<? extends T>>
>> choices) {
>>     super(id, choices);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param model
>>    * @param choices
>>    * @param renderer
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> IModel<T> model,
>>       IModel<List<? extends T>>
>> choices, IChoiceRenderer<T> renderer) {
>>     super(id, model, choices, renderer);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param model
>>    * @param choices
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> IModel<T> model,
>>       IModel<List<? extends T>>
>> choices) {
>>     super(id, model, choices);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param model
>>    * @param data
>>    * @param renderer
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> IModel<T> model,
>>       List<? extends T> data,
>> IChoiceRenderer<T> renderer) {
>>     super(id, model, data, renderer);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param model
>>    * @param choices
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> IModel<T> model,
>>       List<? extends T> choices) {
>>     super(id, model, choices);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param data
>>    * @param renderer
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> List<? extends T> data,
>>       IChoiceRenderer<T> renderer) {
>>     super(id, data, renderer);
>>   }
>>
>>   /**
>>    * @param id
>>    * @param choices
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>> List<? extends T> choices) {
>>     super(id, choices);
>>   }
>>
>>   /**
>>    * @param id
>>    */
>>   public
>> AjaxFormSubmittingChangeListenerDropDownChoice(String id) {
>>     super(id);
>>   }
>> }
>>
>>
>> **
>> Martin
>> 2010/3/21 Sven Meier <sv...@meiers.net>:
>> > David,
>> >
>> >>It seems that you do not understand the problem I
>> have
>> >
>> > obviously not ;).
>> >
>> > A quickstart would help me to understand your problem
>> better, but perhaps
>> > others have already a clue?
>> >
>> > Sven
>> >
>> > David Chang wrote:
>> >>
>> >> Sven,
>> >>
>> >> Thanks for your input. It seems that you do not
>> understand the problem I
>> >> have (Wicket problem??? or my page problem???). I
>> know how Ajax works by
>> >> adding components to Ajax request target.
>> >>
>> >> When it is non-Ajax, my page runs correctly with
>> all three controls. When
>> >> Country DDC Ajax-controls State DDC, the two DDC
>> works correctly. The
>> >> problem is that once this Ajax control is
>> triggered by selecting a value in
>> >> Country DDC, the State DDC list is NOT updated
>> when the Locale DDC value is
>> >> changed.
>> >>
>> >> I have a feel that Wicket has a problem here. I am
>> using Wicket 1.4.7.
>> >>
>> >> Regards.
>> >> -David
>> >>
>> >>
>> >>
>> >> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net>
>> wrote:
>> >>
>> >>
>> >>>
>> >>> From: Sven Meier <sv...@meiers.net>
>> >>> Subject: Re: Ajax has too much control?
>> >>> To: users@wicket.apache.org
>> >>> Date: Sunday, March 21, 2010, 7:25 AM
>> >>> Hi David,
>> >>>
>> >>>
>> DropDownChoice#wantOnSelectionChangedNotifications() will
>> >>> trigger rendering of the complete page.
>> >>> On Ajax request only those components are
>> rendered you
>> >>> explicitely 'add' to the request, see
>> AjaxRequestTarget#addComponent().
>> >>>
>> >>> If you want to have the same for Ajax
>> requests, you can
>> >>> just 'add' the complete page.
>> >>>
>> >>> This is not very efficient though.
>> >>>
>> >>> Sven
>> >>>
>> >>> David Chang wrote:
>> >>>
>> >>>>
>> >>>> Forgive me about this meaningless subject,
>> but I
>> >>>>
>> >>>
>> >>> cannot think of a better one.
>> >>>
>> >>>>
>> >>>> I have been learning Wicket through the
>> WIA book. I
>> >>>>
>> >>>
>> >>> just found out something interesting to me.
>> Not sure it is a
>> >>> bug, design, or something I did wrong.
>> >>>
>> >>>>
>> >>>> I have a page with three Wicket elements:
>> >>>>
>> >>>> 1. Locale selector through a
>> DropDownChoice list. WIA
>> >>>>
>> >>>
>> >>> has complete code about how this works and I
>> copied the
>> >>> solution into this page
>> >>>
>> >>>>
>> >>>> 2. Country DropDownChoice, whose values
>> change between
>> >>>>
>> >>>
>> >>> English and Chinese depending on Locale DDC.
>> >>>>
>> >>>> 3. State DropDownChoice, whose values
>> change between
>> >>>>
>> >>>
>> >>> English and Chinese depending on Locale DDC.
>> The values in
>> >>> this DDC depends on the chosen value in
>> Country DDC.
>> >>>
>> >>>>
>> >>>> Here are the experiments
>> >>>>
>> >>>> Experiment#1.
>> >>>>
>> >>>> Country DDC does not control values in
>> State DDC via
>> >>>>
>> >>>
>> >>> Ajax and it has
>> >>>>
>> >>>> protected boolean
>> >>>>
>> >>>
>> >>> wantOnSelectionChangedNotifications() {
>> >>>
>> >>>>
>> >>>>   return true;
>> >>>> }
>> >>>>
>> >>>> Everything works like a charm, which
>> means
>> >>>> (1) when Country DDC value changes, State
>> DDC changes
>> >>>>
>> >>>
>> >>> accodingly.
>> >>>
>> >>>>
>> >>>> (2) when Locale changes, both Country DDC
>> and State
>> >>>>
>> >>>
>> >>> DDC lists change display values accordingly
>> (which means
>> >>> both DDCs show a list of values in the same
>> language).
>> >>>
>> >>>>
>> >>>> Experiment#2.
>> >>>>
>> >>>> Country DDC controls values in State DDC
>> via Ajax. In
>> >>>>
>> >>>
>> >>> this case, when page is first loaded, I do not
>> touch the
>> >>> Country DDC or State DDC. I simply change
>> locale value any
>> >>> number of times, both Country DDC and State
>> DDC lists change
>> >>> correctly depending on the session locale.
>> Here is the
>> >>> strange thing. Then I change Country DDC
>> value, State DDC
>> >>> changes correctly. Since then, HOWEVER, if I
>> change locale
>> >>> values, ONLY Country DDC list changes
>> correctly; State DDC
>> >>> list is not updated. It seems Wicket decides
>> that State DDC
>> >>> is forever Aja-controlled by Country DDC
>> only.
>> >>>
>> >>>>
>> >>>> Not qure sure if this a bug, design, or I
>> did
>> >>>>
>> >>>
>> >>> something wrong.
>> >>>
>> >>>>
>> >>>> Please let me if you have difficulty
>> understanding the
>> >>>>
>> >>>
>> >>> experiments.
>> >>>
>> >>>>
>> >>>> Thanks for any info or help.
>> >>>>
>> >>>> Cheers!
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> ---------------------------------------------------------------------
>> >>>
>> >>>>
>> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: How to provide a value to a message's argument

Posted by David Chang <da...@yahoo.com>.
Igor, thanks for the info. It worked for me. Just a suggestion. Hope to see a convenience constructor such as:

StringResourceModel(resourceKey, java.lang.Object[] parameters)

In which, model is null. IMHO, Spring has many convenience methods. It would be good to see Wicket does the same (maybe already does it, but I dont know about).

Regards.

--- On Wed, 3/24/10, Igor Vaynberg <ig...@gmail.com> wrote:

> From: Igor Vaynberg <ig...@gmail.com>
> Subject: Re: How to provide a value to a message's argument
> To: users@wicket.apache.org
> Date: Wednesday, March 24, 2010, 11:49 PM
> see StringResourceModel
> 
> -igor
> 
> On Wed, Mar 24, 2010 at 8:42 PM, David Chang <da...@yahoo.com>
> wrote:
> >
> > HTML:
> >
> > <span wicket:id="x">[sample text]</span>
> >
> > Java:
> >
> > add(new Label("x", new ResourceModel("x")));
> >
> > Resource file:
> >
> > <entry key="x">Hello ${label} !</entry>
> >
> > In the above Java, I cannot find a way to provide a
> value to the argument of the string. I want the program to
> display
> >
> > Hello David!
> > Hello Carmen!
> >
> > Regards.
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: How to provide a value to a message's argument

Posted by Igor Vaynberg <ig...@gmail.com>.
see StringResourceModel

-igor

On Wed, Mar 24, 2010 at 8:42 PM, David Chang <da...@yahoo.com> wrote:
>
> HTML:
>
> <span wicket:id="x">[sample text]</span>
>
> Java:
>
> add(new Label("x", new ResourceModel("x")));
>
> Resource file:
>
> <entry key="x">Hello ${label} !</entry>
>
> In the above Java, I cannot find a way to provide a value to the argument of the string. I want the program to display
>
> Hello David!
> Hello Carmen!
>
> Regards.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Reload a page and component repaint

Posted by Igor Vaynberg <ig...@gmail.com>.
it will

-igor

On Tue, Mar 23, 2010 at 7:29 PM, David Chang <da...@yahoo.com> wrote:
>
>> it does, but maybe the model value is unchanged
>
> If the model value is unchanged, the component will repaint itself or not?
>
> Best,
> David
>
> --- On Tue, 3/23/10, Igor Vaynberg <ig...@gmail.com> wrote:
>
>> From: Igor Vaynberg <ig...@gmail.com>
>> Subject: Re: Reload a page and component repaint
>> To: users@wicket.apache.org
>> Date: Tuesday, March 23, 2010, 10:24 PM
>> On Tue, Mar 23, 2010 at 7:13 PM,
>> David Chang <da...@yahoo.com>
>> wrote:
>> > I am new in Wicket and so please bear with me if this
>> question is obvious.
>> >
>> > Suppose I am viewing a Wicket page in FF. At the
>> moment, the link is:
>> >
>> > http://localhost:8080/f/?wicket:interface=:12::::
>> >
>> > If I click the Reload button of FF, isn't Wicket
>> supposed to call EACH component to repaint itself based on
>> its model value?
>>
>> it does, but maybe the model value is unchanged
>>
>> -igor
>>
>> >
>> > If not, then what are the circumstances to prevent a
>> component from repainting itself? How can I force a
>> component get repainted.
>> >
>> > Thanks!
>> >
>> >
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Reload a page and component repaint

Posted by David Chang <da...@yahoo.com>.
> it does, but maybe the model value is unchanged

If the model value is unchanged, the component will repaint itself or not?

Best,
David

--- On Tue, 3/23/10, Igor Vaynberg <ig...@gmail.com> wrote:

> From: Igor Vaynberg <ig...@gmail.com>
> Subject: Re: Reload a page and component repaint
> To: users@wicket.apache.org
> Date: Tuesday, March 23, 2010, 10:24 PM
> On Tue, Mar 23, 2010 at 7:13 PM,
> David Chang <da...@yahoo.com>
> wrote:
> > I am new in Wicket and so please bear with me if this
> question is obvious.
> >
> > Suppose I am viewing a Wicket page in FF. At the
> moment, the link is:
> >
> > http://localhost:8080/f/?wicket:interface=:12::::
> >
> > If I click the Reload button of FF, isn't Wicket
> supposed to call EACH component to repaint itself based on
> its model value?
> 
> it does, but maybe the model value is unchanged
> 
> -igor
> 
> >
> > If not, then what are the circumstances to prevent a
> component from repainting itself? How can I force a
> component get repainted.
> >
> > Thanks!
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: Reload a page and component repaint

Posted by Igor Vaynberg <ig...@gmail.com>.
On Tue, Mar 23, 2010 at 7:13 PM, David Chang <da...@yahoo.com> wrote:
> I am new in Wicket and so please bear with me if this question is obvious.
>
> Suppose I am viewing a Wicket page in FF. At the moment, the link is:
>
> http://localhost:8080/f/?wicket:interface=:12::::
>
> If I click the Reload button of FF, isn't Wicket supposed to call EACH component to repaint itself based on its model value?

it does, but maybe the model value is unchanged

-igor

>
> If not, then what are the circumstances to prevent a component from repainting itself? How can I force a component get repainted.
>
> Thanks!
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


How to provide a value to a message's argument

Posted by David Chang <da...@yahoo.com>.
HTML:

<span wicket:id="x">[sample text]</span>

Java:

add(new Label("x", new ResourceModel("x")));

Resource file:

<entry key="x">Hello ${label} !</entry>

In the above Java, I cannot find a way to provide a value to the argument of the string. I want the program to display 

Hello David! 
Hello Carmen!

Regards.


      

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


Re: Reasons against using Acegi with Wicket?

Posted by David Chang <da...@yahoo.com>.
James, 

I did read some of your code for clues regarding how to program Wicket. Glad to know that it even has Acegi integration there!!!

Best,
David

--- On Mon, 3/22/10, James Carman <jc...@carmanconsulting.com> wrote:

> From: James Carman <jc...@carmanconsulting.com>
> Subject: Re: Reasons against using Acegi with Wicket?
> To: users@wicket.apache.org
> Date: Monday, March 22, 2010, 8:29 AM
> David,
> 
> My example application I pointed out to you contains a
> Spring Security
> (formerly Acegi) configuration for Wicket (with a
> superclass for the
> application/session).  That should help get you off
> the ground quickly
> if you want to go with Spring Security.
> 
> James
> 
> On Mon, Mar 22, 2010 at 8:15 AM, David Chang <da...@yahoo.com>
> wrote:
> >
> > Hello, I am learning Wicekt via the book WIA and I
> understand that Wicket has its own way (interfaces,
> components, sub-projects) of handling web security.
> >
> > I am thinking about using Acegi with Wicket. The
> reason is that I am familiar with Acegi, but I hope I am not
> going to do the wrong thing within the Wicket context.
> >
> > I would like to know any big or obvious reasons
> against that.
> >
> > Thanks for your input!
> >
> > Regards.
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Reload a page and component repaint

Posted by David Chang <da...@yahoo.com>.
I am new in Wicket and so please bear with me if this question is obvious.

Suppose I am viewing a Wicket page in FF. At the moment, the link is:

http://localhost:8080/f/?wicket:interface=:12::::

If I click the Reload button of FF, isn't Wicket supposed to call EACH component to repaint itself based on its model value? 

If not, then what are the circumstances to prevent a component from repainting itself? How can I force a component get repainted.

Thanks!


      

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


Re: Reasons against using Acegi with Wicket?

Posted by James Carman <jc...@carmanconsulting.com>.
David,

My example application I pointed out to you contains a Spring Security
(formerly Acegi) configuration for Wicket (with a superclass for the
application/session).  That should help get you off the ground quickly
if you want to go with Spring Security.

James

On Mon, Mar 22, 2010 at 8:15 AM, David Chang <da...@yahoo.com> wrote:
>
> Hello, I am learning Wicekt via the book WIA and I understand that Wicket has its own way (interfaces, components, sub-projects) of handling web security.
>
> I am thinking about using Acegi with Wicket. The reason is that I am familiar with Acegi, but I hope I am not going to do the wrong thing within the Wicket context.
>
> I would like to know any big or obvious reasons against that.
>
> Thanks for your input!
>
> Regards.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Reasons against using Acegi with Wicket?

Posted by David Chang <da...@yahoo.com>.
Hello, I am learning Wicekt via the book WIA and I understand that Wicket has its own way (interfaces, components, sub-projects) of handling web security.

I am thinking about using Acegi with Wicket. The reason is that I am familiar with Acegi, but I hope I am not going to do the wrong thing within the Wicket context.

I would like to know any big or obvious reasons against that.

Thanks for your input!

Regards.


      

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


Re: Ajax has too much control?

Posted by David Chang <da...@yahoo.com>.
Hello Martin,

Thanks for your input and sharing your code! I will give it a try. 

Did you have the same problem I have now?

Here is what I have for the Country DDC:

countryDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
    protected void onUpdate(AjaxRequestTarget target) {
    	if (target != null) {
      	MyUser u = form.getModelObject();
      	u.setState(null);
      	DropDownChoice stateDDC = (DropDownChoice) form.get("state");
      	stateDDC.setChoices(objectService.findStatesForLocale(getSession().getLocale()));
        target.addComponent(countryDDC);
        target.addComponent(stateDDC);
        }
    }
});


As you can see, I am using AjaxFormComponentUpdatingBehavior. Why do you use AjaxFormSubmitBehavior? In my case, I am not submitting a form.

I am new in Wicket. Thanks for your help!

Best.
-David





--- On Sun, 3/21/10, Martin Makundi <ma...@koodaripalvelut.com> wrote:

> From: Martin Makundi <ma...@koodaripalvelut.com>
> Subject: Re: Ajax has too much control?
> To: users@wicket.apache.org
> Date: Sunday, March 21, 2010, 11:38 AM
> Hi David!
> 
> Maybe you need this (at least this is what worked for me):
> 
> /**
>  * @author Martin
>  */
> public abstract class
> AjaxFormSubmittingChangeListenerBehavior extends
>     AjaxFormSubmitBehavior {
>   private final static Method hiddenFieldGetter;
>   static {
>     try {
>       hiddenFieldGetter =
> Form.class.getDeclaredMethod("getHiddenFieldId");
>      
> hiddenFieldGetter.setAccessible(true);
>     } catch (Exception e) {
>       throw new RuntimeException(e);
>     }
>   }
> 
>   /**
>    * @see
> org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
>    */
>   @Override
>   protected void onBind() {
>     super.onBind();
> 
>     if (!(getComponent() instanceof
> IOnChangeListener))
>     {
>       throw new
> WicketRuntimeException("Behavior " + getClass().getName() +
>         " can only be added to an
> instance of a IOnChangeListener");
>     }
>   }
> 
>   /**
>    * @param event
>    */
>   public
> AjaxFormSubmittingChangeListenerBehavior(String event) {
>     super(event);
>   }
> 
>   /**
>    * @see
> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
>    */
>   @Override
>   protected void onError(AjaxRequestTarget target) {
>     onSubmit(target);
>   }
> 
>   /**
>    * @see
> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
>    */
>   @Override
>   protected void onEvent(AjaxRequestTarget target) {
>     HttpServletRequest httpServletRequest =
> ((WebRequest) getComponent()
>        
> .getRequest()).getHttpServletRequest();
> 
>     Map parameters;
> 
>     if (httpServletRequest instanceof
> MockHttpServletRequest) {
>       parameters =
> ((MockHttpServletRequest)
> httpServletRequest).getParameterMap();
>     } else {
>       parameters =
> ((org.mortbay.jetty.Request)
> httpServletRequest).getParameters();
>     }
> 
>     parameters.put(getHiddenFieldId(getForm()),
> getComponent().urlFor(IOnChangeListener.INTERFACE));
> 
>     final FormComponent<?> formComponent =
> (FormComponent<?>) getComponent();
> 
>     try {
>       if (isUpdateModel()) {
>         formComponent.inputChanged();
>         formComponent.validate();
> 
>         if
> (!formComponent.hasErrorMessage()) {
>           formComponent.valid();
>          
> formComponent.updateModel();
>         }
>       }
> 
>       super.onEvent(target);
>     } catch (RuntimeException e) {
>      
> Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class,
> e);
>       onError(target);
>     }
>   }
> 
>   /**
>    * @return boolean
>    */
>   protected boolean isUpdateModel() {
>     return true;
>   }
> 
>   /**
>    * @param form
>    * @return String
>    */
>   private String getHiddenFieldId(Form<?> form)
> {
>     try {
>       Form<?> root =
> form.getRootForm();
>       return (String)
> hiddenFieldGetter.invoke(root);
>     } catch (Exception e) {
>       throw new RuntimeException(e);
>     }
>   }
> }
> 
> 
> public abstract class
> AjaxFormSubmittingChangeListenerDropDownChoice<T>
> extends
> DropDownChoice<T> {
>   /** Initialize */ {
>     add(new
> AjaxFormSubmittingChangeListenerBehavior(JavaScriptConstants.ONCHANGE)
> {
>       @Override
>       protected void
> onSubmit(AjaxRequestTarget target) {
>        
> AjaxFormSubmittingChangeListenerDropDownChoice.this.onSubmit(target);
>       }
>     });
>   }
> 
>   /**
>    * @see
> org.apache.wicket.MarkupContainer#toString()
>    */
>   @Override
>   public String toString() {
>     return super.toString() + " Value: " +
> getValue();
>   }
> 
>   /**
>    * @param id
>    * @param choices
>    * @param renderer
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>       IModel<List<? extends T>>
> choices, IChoiceRenderer<T> renderer) {
>     super(id, choices, renderer);
>   }
> 
>   /**
>    * @param target
>    */
>   protected abstract void onSubmit(AjaxRequestTarget
> target);
> 
>   /**
>    * @param target
>    */
>   protected void onError(AjaxRequestTarget target) {
>     onSubmit(target);
>   }
> 
>   /**
>    * @param id
>    * @param choices
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
>       IModel<List<? extends T>>
> choices) {
>     super(id, choices);
>   }
> 
>   /**
>    * @param id
>    * @param model
>    * @param choices
>    * @param renderer
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> IModel<T> model,
>       IModel<List<? extends T>>
> choices, IChoiceRenderer<T> renderer) {
>     super(id, model, choices, renderer);
>   }
> 
>   /**
>    * @param id
>    * @param model
>    * @param choices
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> IModel<T> model,
>       IModel<List<? extends T>>
> choices) {
>     super(id, model, choices);
>   }
> 
>   /**
>    * @param id
>    * @param model
>    * @param data
>    * @param renderer
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> IModel<T> model,
>       List<? extends T> data,
> IChoiceRenderer<T> renderer) {
>     super(id, model, data, renderer);
>   }
> 
>   /**
>    * @param id
>    * @param model
>    * @param choices
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> IModel<T> model,
>       List<? extends T> choices) {
>     super(id, model, choices);
>   }
> 
>   /**
>    * @param id
>    * @param data
>    * @param renderer
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> List<? extends T> data,
>       IChoiceRenderer<T> renderer) {
>     super(id, data, renderer);
>   }
> 
>   /**
>    * @param id
>    * @param choices
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id,
> List<? extends T> choices) {
>     super(id, choices);
>   }
> 
>   /**
>    * @param id
>    */
>   public
> AjaxFormSubmittingChangeListenerDropDownChoice(String id) {
>     super(id);
>   }
> }
> 
> 
> **
> Martin
> 2010/3/21 Sven Meier <sv...@meiers.net>:
> > David,
> >
> >>It seems that you do not understand the problem I
> have
> >
> > obviously not ;).
> >
> > A quickstart would help me to understand your problem
> better, but perhaps
> > others have already a clue?
> >
> > Sven
> >
> > David Chang wrote:
> >>
> >> Sven,
> >>
> >> Thanks for your input. It seems that you do not
> understand the problem I
> >> have (Wicket problem??? or my page problem???). I
> know how Ajax works by
> >> adding components to Ajax request target.
> >>
> >> When it is non-Ajax, my page runs correctly with
> all three controls. When
> >> Country DDC Ajax-controls State DDC, the two DDC
> works correctly. The
> >> problem is that once this Ajax control is
> triggered by selecting a value in
> >> Country DDC, the State DDC list is NOT updated
> when the Locale DDC value is
> >> changed.
> >>
> >> I have a feel that Wicket has a problem here. I am
> using Wicket 1.4.7.
> >>
> >> Regards.
> >> -David
> >>
> >>
> >>
> >> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net>
> wrote:
> >>
> >>
> >>>
> >>> From: Sven Meier <sv...@meiers.net>
> >>> Subject: Re: Ajax has too much control?
> >>> To: users@wicket.apache.org
> >>> Date: Sunday, March 21, 2010, 7:25 AM
> >>> Hi David,
> >>>
> >>>
> DropDownChoice#wantOnSelectionChangedNotifications() will
> >>> trigger rendering of the complete page.
> >>> On Ajax request only those components are
> rendered you
> >>> explicitely 'add' to the request, see
> AjaxRequestTarget#addComponent().
> >>>
> >>> If you want to have the same for Ajax
> requests, you can
> >>> just 'add' the complete page.
> >>>
> >>> This is not very efficient though.
> >>>
> >>> Sven
> >>>
> >>> David Chang wrote:
> >>>
> >>>>
> >>>> Forgive me about this meaningless subject,
> but I
> >>>>
> >>>
> >>> cannot think of a better one.
> >>>
> >>>>
> >>>> I have been learning Wicket through the
> WIA book. I
> >>>>
> >>>
> >>> just found out something interesting to me.
> Not sure it is a
> >>> bug, design, or something I did wrong.
> >>>
> >>>>
> >>>> I have a page with three Wicket elements:
> >>>>
> >>>> 1. Locale selector through a
> DropDownChoice list. WIA
> >>>>
> >>>
> >>> has complete code about how this works and I
> copied the
> >>> solution into this page
> >>>
> >>>>
> >>>> 2. Country DropDownChoice, whose values
> change between
> >>>>
> >>>
> >>> English and Chinese depending on Locale DDC.
> >>>>
> >>>> 3. State DropDownChoice, whose values
> change between
> >>>>
> >>>
> >>> English and Chinese depending on Locale DDC.
> The values in
> >>> this DDC depends on the chosen value in
> Country DDC.
> >>>
> >>>>
> >>>> Here are the experiments
> >>>>
> >>>> Experiment#1.
> >>>>
> >>>> Country DDC does not control values in
> State DDC via
> >>>>
> >>>
> >>> Ajax and it has
> >>>>
> >>>> protected boolean
> >>>>
> >>>
> >>> wantOnSelectionChangedNotifications() {
> >>>
> >>>>
> >>>>   return true;
> >>>> }
> >>>>
> >>>> Everything works like a charm, which
> means
> >>>> (1) when Country DDC value changes, State
> DDC changes
> >>>>
> >>>
> >>> accodingly.
> >>>
> >>>>
> >>>> (2) when Locale changes, both Country DDC
> and State
> >>>>
> >>>
> >>> DDC lists change display values accordingly
> (which means
> >>> both DDCs show a list of values in the same
> language).
> >>>
> >>>>
> >>>> Experiment#2.
> >>>>
> >>>> Country DDC controls values in State DDC
> via Ajax. In
> >>>>
> >>>
> >>> this case, when page is first loaded, I do not
> touch the
> >>> Country DDC or State DDC. I simply change
> locale value any
> >>> number of times, both Country DDC and State
> DDC lists change
> >>> correctly depending on the session locale.
> Here is the
> >>> strange thing. Then I change Country DDC
> value, State DDC
> >>> changes correctly. Since then, HOWEVER, if I
> change locale
> >>> values, ONLY Country DDC list changes
> correctly; State DDC
> >>> list is not updated. It seems Wicket decides
> that State DDC
> >>> is forever Aja-controlled by Country DDC
> only.
> >>>
> >>>>
> >>>> Not qure sure if this a bug, design, or I
> did
> >>>>
> >>>
> >>> something wrong.
> >>>
> >>>>
> >>>> Please let me if you have difficulty
> understanding the
> >>>>
> >>>
> >>> experiments.
> >>>
> >>>>
> >>>> Thanks for any info or help.
> >>>>
> >>>> Cheers!
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> ---------------------------------------------------------------------
> >>>
> >>>>
> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: Ajax has too much control?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Hi David!

Maybe you need this (at least this is what worked for me):

/**
 * @author Martin
 */
public abstract class AjaxFormSubmittingChangeListenerBehavior extends
    AjaxFormSubmitBehavior {
  private final static Method hiddenFieldGetter;
  static {
    try {
      hiddenFieldGetter = Form.class.getDeclaredMethod("getHiddenFieldId");
      hiddenFieldGetter.setAccessible(true);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  /**
   * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
   */
  @Override
  protected void onBind() {
    super.onBind();

    if (!(getComponent() instanceof IOnChangeListener))
    {
      throw new WicketRuntimeException("Behavior " + getClass().getName() +
        " can only be added to an instance of a IOnChangeListener");
    }
  }

  /**
   * @param event
   */
  public AjaxFormSubmittingChangeListenerBehavior(String event) {
    super(event);
  }

  /**
   * @see org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
   */
  @Override
  protected void onError(AjaxRequestTarget target) {
    onSubmit(target);
  }

  /**
   * @see org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
   */
  @Override
  protected void onEvent(AjaxRequestTarget target) {
    HttpServletRequest httpServletRequest = ((WebRequest) getComponent()
        .getRequest()).getHttpServletRequest();

    Map parameters;

    if (httpServletRequest instanceof MockHttpServletRequest) {
      parameters = ((MockHttpServletRequest)
httpServletRequest).getParameterMap();
    } else {
      parameters = ((org.mortbay.jetty.Request)
httpServletRequest).getParameters();
    }

    parameters.put(getHiddenFieldId(getForm()),
getComponent().urlFor(IOnChangeListener.INTERFACE));

    final FormComponent<?> formComponent = (FormComponent<?>) getComponent();

    try {
      if (isUpdateModel()) {
        formComponent.inputChanged();
        formComponent.validate();

        if (!formComponent.hasErrorMessage()) {
          formComponent.valid();
          formComponent.updateModel();
        }
      }

      super.onEvent(target);
    } catch (RuntimeException e) {
      Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class, e);
      onError(target);
    }
  }

  /**
   * @return boolean
   */
  protected boolean isUpdateModel() {
    return true;
  }

  /**
   * @param form
   * @return String
   */
  private String getHiddenFieldId(Form<?> form) {
    try {
      Form<?> root = form.getRootForm();
      return (String) hiddenFieldGetter.invoke(root);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}


public abstract class
AjaxFormSubmittingChangeListenerDropDownChoice<T> extends
DropDownChoice<T> {
  /** Initialize */ {
    add(new AjaxFormSubmittingChangeListenerBehavior(JavaScriptConstants.ONCHANGE)
{
      @Override
      protected void onSubmit(AjaxRequestTarget target) {
        AjaxFormSubmittingChangeListenerDropDownChoice.this.onSubmit(target);
      }
    });
  }

  /**
   * @see org.apache.wicket.MarkupContainer#toString()
   */
  @Override
  public String toString() {
    return super.toString() + " Value: " + getValue();
  }

  /**
   * @param id
   * @param choices
   * @param renderer
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
      IModel<List<? extends T>> choices, IChoiceRenderer<T> renderer) {
    super(id, choices, renderer);
  }

  /**
   * @param target
   */
  protected abstract void onSubmit(AjaxRequestTarget target);

  /**
   * @param target
   */
  protected void onError(AjaxRequestTarget target) {
    onSubmit(target);
  }

  /**
   * @param id
   * @param choices
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
      IModel<List<? extends T>> choices) {
    super(id, choices);
  }

  /**
   * @param id
   * @param model
   * @param choices
   * @param renderer
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
IModel<T> model,
      IModel<List<? extends T>> choices, IChoiceRenderer<T> renderer) {
    super(id, model, choices, renderer);
  }

  /**
   * @param id
   * @param model
   * @param choices
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
IModel<T> model,
      IModel<List<? extends T>> choices) {
    super(id, model, choices);
  }

  /**
   * @param id
   * @param model
   * @param data
   * @param renderer
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
IModel<T> model,
      List<? extends T> data, IChoiceRenderer<T> renderer) {
    super(id, model, data, renderer);
  }

  /**
   * @param id
   * @param model
   * @param choices
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
IModel<T> model,
      List<? extends T> choices) {
    super(id, model, choices);
  }

  /**
   * @param id
   * @param data
   * @param renderer
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
List<? extends T> data,
      IChoiceRenderer<T> renderer) {
    super(id, data, renderer);
  }

  /**
   * @param id
   * @param choices
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id,
List<? extends T> choices) {
    super(id, choices);
  }

  /**
   * @param id
   */
  public AjaxFormSubmittingChangeListenerDropDownChoice(String id) {
    super(id);
  }
}


**
Martin
2010/3/21 Sven Meier <sv...@meiers.net>:
> David,
>
>>It seems that you do not understand the problem I have
>
> obviously not ;).
>
> A quickstart would help me to understand your problem better, but perhaps
> others have already a clue?
>
> Sven
>
> David Chang wrote:
>>
>> Sven,
>>
>> Thanks for your input. It seems that you do not understand the problem I
>> have (Wicket problem??? or my page problem???). I know how Ajax works by
>> adding components to Ajax request target.
>>
>> When it is non-Ajax, my page runs correctly with all three controls. When
>> Country DDC Ajax-controls State DDC, the two DDC works correctly. The
>> problem is that once this Ajax control is triggered by selecting a value in
>> Country DDC, the State DDC list is NOT updated when the Locale DDC value is
>> changed.
>>
>> I have a feel that Wicket has a problem here. I am using Wicket 1.4.7.
>>
>> Regards.
>> -David
>>
>>
>>
>> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net> wrote:
>>
>>
>>>
>>> From: Sven Meier <sv...@meiers.net>
>>> Subject: Re: Ajax has too much control?
>>> To: users@wicket.apache.org
>>> Date: Sunday, March 21, 2010, 7:25 AM
>>> Hi David,
>>>
>>> DropDownChoice#wantOnSelectionChangedNotifications() will
>>> trigger rendering of the complete page.
>>> On Ajax request only those components are rendered you
>>> explicitely 'add' to the request, see AjaxRequestTarget#addComponent().
>>>
>>> If you want to have the same for Ajax requests, you can
>>> just 'add' the complete page.
>>>
>>> This is not very efficient though.
>>>
>>> Sven
>>>
>>> David Chang wrote:
>>>
>>>>
>>>> Forgive me about this meaningless subject, but I
>>>>
>>>
>>> cannot think of a better one.
>>>
>>>>
>>>> I have been learning Wicket through the WIA book. I
>>>>
>>>
>>> just found out something interesting to me. Not sure it is a
>>> bug, design, or something I did wrong.
>>>
>>>>
>>>> I have a page with three Wicket elements:
>>>>
>>>> 1. Locale selector through a DropDownChoice list. WIA
>>>>
>>>
>>> has complete code about how this works and I copied the
>>> solution into this page
>>>
>>>>
>>>> 2. Country DropDownChoice, whose values change between
>>>>
>>>
>>> English and Chinese depending on Locale DDC.
>>>>
>>>> 3. State DropDownChoice, whose values change between
>>>>
>>>
>>> English and Chinese depending on Locale DDC. The values in
>>> this DDC depends on the chosen value in Country DDC.
>>>
>>>>
>>>> Here are the experiments
>>>>
>>>> Experiment#1.
>>>>
>>>> Country DDC does not control values in State DDC via
>>>>
>>>
>>> Ajax and it has
>>>>
>>>> protected boolean
>>>>
>>>
>>> wantOnSelectionChangedNotifications() {
>>>
>>>>
>>>>   return true;
>>>> }
>>>>
>>>> Everything works like a charm, which means
>>>> (1) when Country DDC value changes, State DDC changes
>>>>
>>>
>>> accodingly.
>>>
>>>>
>>>> (2) when Locale changes, both Country DDC and State
>>>>
>>>
>>> DDC lists change display values accordingly (which means
>>> both DDCs show a list of values in the same language).
>>>
>>>>
>>>> Experiment#2.
>>>>
>>>> Country DDC controls values in State DDC via Ajax. In
>>>>
>>>
>>> this case, when page is first loaded, I do not touch the
>>> Country DDC or State DDC. I simply change locale value any
>>> number of times, both Country DDC and State DDC lists change
>>> correctly depending on the session locale. Here is the
>>> strange thing. Then I change Country DDC value, State DDC
>>> changes correctly. Since then, HOWEVER, if I change locale
>>> values, ONLY Country DDC list changes correctly; State DDC
>>> list is not updated. It seems Wicket decides that State DDC
>>> is forever Aja-controlled by Country DDC only.
>>>
>>>>
>>>> Not qure sure if this a bug, design, or I did
>>>>
>>>
>>> something wrong.
>>>
>>>>
>>>> Please let me if you have difficulty understanding the
>>>>
>>>
>>> experiments.
>>>
>>>>
>>>> Thanks for any info or help.
>>>>
>>>> Cheers!
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>>
>>>>
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Ajax has too much control?

Posted by Sven Meier <sv...@meiers.net>.
David,

 >It seems that you do not understand the problem I have

obviously not ;).

A quickstart would help me to understand your problem better, but 
perhaps others have already a clue?

Sven

David Chang wrote:
> Sven,
>
> Thanks for your input. It seems that you do not understand the problem I have (Wicket problem??? or my page problem???). I know how Ajax works by adding components to Ajax request target.
>
> When it is non-Ajax, my page runs correctly with all three controls. When Country DDC Ajax-controls State DDC, the two DDC works correctly. The problem is that once this Ajax control is triggered by selecting a value in Country DDC, the State DDC list is NOT updated when the Locale DDC value is changed.
>
> I have a feel that Wicket has a problem here. I am using Wicket 1.4.7.
>
> Regards.
> -David
>
>
>
> --- On Sun, 3/21/10, Sven Meier <sv...@meiers.net> wrote:
>
>   
>> From: Sven Meier <sv...@meiers.net>
>> Subject: Re: Ajax has too much control?
>> To: users@wicket.apache.org
>> Date: Sunday, March 21, 2010, 7:25 AM
>> Hi David,
>>
>> DropDownChoice#wantOnSelectionChangedNotifications() will
>> trigger 
>> rendering of the complete page.
>> On Ajax request only those components are rendered you
>> explicitely 'add' 
>> to the request, see AjaxRequestTarget#addComponent().
>>
>> If you want to have the same for Ajax requests, you can
>> just 'add' the 
>> complete page.
>>
>> This is not very efficient though.
>>
>> Sven
>>
>> David Chang wrote:
>>     
>>> Forgive me about this meaningless subject, but I
>>>       
>> cannot think of a better one.
>>     
>>> I have been learning Wicket through the WIA book. I
>>>       
>> just found out something interesting to me. Not sure it is a
>> bug, design, or something I did wrong.
>>     
>>> I have a page with three Wicket elements:
>>>
>>> 1. Locale selector through a DropDownChoice list. WIA
>>>       
>> has complete code about how this works and I copied the
>> solution into this page
>>     
>>> 2. Country DropDownChoice, whose values change between
>>>       
>> English and Chinese depending on Locale DDC. 
>>     
>>> 3. State DropDownChoice, whose values change between
>>>       
>> English and Chinese depending on Locale DDC. The values in
>> this DDC depends on the chosen value in Country DDC.
>>     
>>> Here are the experiments
>>>
>>> Experiment#1.
>>>
>>> Country DDC does not control values in State DDC via
>>>       
>> Ajax and it has 
>>     
>>> protected boolean
>>>       
>> wantOnSelectionChangedNotifications() {
>>     
>>>    return true;
>>> }
>>>
>>> Everything works like a charm, which means 
>>>
>>> (1) when Country DDC value changes, State DDC changes
>>>       
>> accodingly.
>>     
>>> (2) when Locale changes, both Country DDC and State
>>>       
>> DDC lists change display values accordingly (which means
>> both DDCs show a list of values in the same language).
>>     
>>> Experiment#2.
>>>
>>> Country DDC controls values in State DDC via Ajax. In
>>>       
>> this case, when page is first loaded, I do not touch the
>> Country DDC or State DDC. I simply change locale value any
>> number of times, both Country DDC and State DDC lists change
>> correctly depending on the session locale. Here is the
>> strange thing. Then I change Country DDC value, State DDC
>> changes correctly. Since then, HOWEVER, if I change locale
>> values, ONLY Country DDC list changes correctly; State DDC
>> list is not updated. It seems Wicket decides that State DDC
>> is forever Aja-controlled by Country DDC only.
>>     
>>> Not qure sure if this a bug, design, or I did
>>>       
>> something wrong.
>>     
>>> Please let me if you have difficulty understanding the
>>>       
>> experiments.
>>     
>>> Thanks for any info or help.
>>>
>>> Cheers!
>>>
>>>
>>>
>>>        
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>>     
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>    
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


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


Re: Ajax has too much control?

Posted by David Chang <da...@yahoo.com>.
Sven,

Thanks for your input. It seems that you do not understand the problem I have (Wicket problem??? or my page problem???). I know how Ajax works by adding components to Ajax request target.

When it is non-Ajax, my page runs correctly with all three controls. When Country DDC Ajax-controls State DDC, the two DDC works correctly. The problem is that once this Ajax control is triggered by selecting a value in Country DDC, the State DDC list is NOT updated when the Locale DDC value is changed.

I have a feel that Wicket has a problem here. I am using Wicket 1.4.7.

Regards.
-David



--- On Sun, 3/21/10, Sven Meier <sv...@meiers.net> wrote:

> From: Sven Meier <sv...@meiers.net>
> Subject: Re: Ajax has too much control?
> To: users@wicket.apache.org
> Date: Sunday, March 21, 2010, 7:25 AM
> Hi David,
> 
> DropDownChoice#wantOnSelectionChangedNotifications() will
> trigger 
> rendering of the complete page.
> On Ajax request only those components are rendered you
> explicitely 'add' 
> to the request, see AjaxRequestTarget#addComponent().
> 
> If you want to have the same for Ajax requests, you can
> just 'add' the 
> complete page.
> 
> This is not very efficient though.
> 
> Sven
> 
> David Chang wrote:
> > Forgive me about this meaningless subject, but I
> cannot think of a better one.
> >
> > I have been learning Wicket through the WIA book. I
> just found out something interesting to me. Not sure it is a
> bug, design, or something I did wrong.
> >
> > I have a page with three Wicket elements:
> >
> > 1. Locale selector through a DropDownChoice list. WIA
> has complete code about how this works and I copied the
> solution into this page
> >
> > 2. Country DropDownChoice, whose values change between
> English and Chinese depending on Locale DDC. 
> >
> > 3. State DropDownChoice, whose values change between
> English and Chinese depending on Locale DDC. The values in
> this DDC depends on the chosen value in Country DDC.
> >
> > Here are the experiments
> >
> > Experiment#1.
> >
> > Country DDC does not control values in State DDC via
> Ajax and it has 
> >
> > protected boolean
> wantOnSelectionChangedNotifications() {
> >   return true;
> > }
> >
> > Everything works like a charm, which means 
> >
> > (1) when Country DDC value changes, State DDC changes
> accodingly.
> > (2) when Locale changes, both Country DDC and State
> DDC lists change display values accordingly (which means
> both DDCs show a list of values in the same language).
> >
> > Experiment#2.
> >
> > Country DDC controls values in State DDC via Ajax. In
> this case, when page is first loaded, I do not touch the
> Country DDC or State DDC. I simply change locale value any
> number of times, both Country DDC and State DDC lists change
> correctly depending on the session locale. Here is the
> strange thing. Then I change Country DDC value, State DDC
> changes correctly. Since then, HOWEVER, if I change locale
> values, ONLY Country DDC list changes correctly; State DDC
> list is not updated. It seems Wicket decides that State DDC
> is forever Aja-controlled by Country DDC only.
> >
> > Not qure sure if this a bug, design, or I did
> something wrong.
> >
> > Please let me if you have difficulty understanding the
> experiments.
> >
> > Thanks for any info or help.
> >
> > Cheers!
> >
> >
> >
> >       
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> >   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

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


Re: Ajax has too much control?

Posted by Sven Meier <sv...@meiers.net>.
Hi David,

DropDownChoice#wantOnSelectionChangedNotifications() will trigger 
rendering of the complete page.
On Ajax request only those components are rendered you explicitely 'add' 
to the request, see AjaxRequestTarget#addComponent().

If you want to have the same for Ajax requests, you can just 'add' the 
complete page.

This is not very efficient though.

Sven

David Chang wrote:
> Forgive me about this meaningless subject, but I cannot think of a better one.
>
> I have been learning Wicket through the WIA book. I just found out something interesting to me. Not sure it is a bug, design, or something I did wrong.
>
> I have a page with three Wicket elements:
>
> 1. Locale selector through a DropDownChoice list. WIA has complete code about how this works and I copied the solution into this page
>
> 2. Country DropDownChoice, whose values change between English and Chinese depending on Locale DDC. 
>
> 3. State DropDownChoice, whose values change between English and Chinese depending on Locale DDC. The values in this DDC depends on the chosen value in Country DDC.
>
> Here are the experiments
>
> Experiment#1.
>
> Country DDC does not control values in State DDC via Ajax and it has 
>
> protected boolean wantOnSelectionChangedNotifications() {
>   return true;
> }
>
> Everything works like a charm, which means 
>
> (1) when Country DDC value changes, State DDC changes accodingly.
> (2) when Locale changes, both Country DDC and State DDC lists change display values accordingly (which means both DDCs show a list of values in the same language).
>
> Experiment#2.
>
> Country DDC controls values in State DDC via Ajax. In this case, when page is first loaded, I do not touch the Country DDC or State DDC. I simply change locale value any number of times, both Country DDC and State DDC lists change correctly depending on the session locale. Here is the strange thing. Then I change Country DDC value, State DDC changes correctly. Since then, HOWEVER, if I change locale values, ONLY Country DDC list changes correctly; State DDC list is not updated. It seems Wicket decides that State DDC is forever Aja-controlled by Country DDC only.
>
> Not qure sure if this a bug, design, or I did something wrong.
>
> Please let me if you have difficulty understanding the experiments.
>
> Thanks for any info or help.
>
> Cheers!
>
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   


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