You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Berlin Brown <be...@gmail.com> on 2010/06/26 17:47:22 UTC

Re: Wicket: On RadioChoice component, invoke form submit, what am I missing

On Sat, Jun 26, 2010 at 6:01 AM, Martin Grigorov
<ma...@yahoo.com>wrote:

> You need to use either pure Javascript:
> 1) <input type="radio" onchange="this.form.submit();"/"
>
> or Ajax:
> 2) radioGroup.add(new AjaxFormSubmitBehavior("onchange") {public void
> onSubmit(AjaxRequestTarget target) {...}}
>
> On Fri, 2010-06-25 at 14:09 -0400, Brown, Berlin [GCG-PFS] wrote:
> > There are some components in wicket that seem to be associated with a
> > form, but I can't get them to actually submit the form.
> >
> > Or at least, I can't get them to submit the form, if I have a hierarchy
> > of FORM -> PANEL -> COMPONENT/RADIOCHOICE
> >
> > For example, I can create a "submitlink" or button and those components
> > submit:
> >
> > return new SubmitLink(id, form) {
> >    @Override
> >    public void onSubmit() {
> >     this.setResponsePage(pageClass);
> >    }
> >   };
> >
> > That works above.
> >
> > I want to be able to perform a submit on a radio choice, on change. E.g.
> >
> > new OnChangeHandler() {
> >
> >      @Override
> >      public void onChange(final Object sel) {
> >       // On submission, submit back to form
> >       setResponsePage(Page.class);
> >      }
> >
> > // MY CONTAINER IS NOT A FORM BUT A CHILD OF A FORM (E.g. FORM -> PANEL
> > -> RADIOCHOICE
> >
> > public RadioChoice addRadioGroup(final WebMarkupContainer container,
> > final Object modelObject,
> >    final String groupName, final String propFieldName, final String []
> > optionsArr, final OnChangeHandler handler) {
> >
> >   final RadioChoice radioGroupYesNo = new RadioChoice(groupName, new
> > PropertyModel(modelObject, propFieldName), Arrays.asList(optionsArr)) {
> >
> >          @Override
> >    public boolean wantOnSelectionChangedNotifications() {
> >     return (handler != null); /* When the handler is not null, enable on
> > change */
> >    }
> >    @Override
> >    public void onSelectionChanged(Object newSel) {
> >     if (handler != null) {
> >      handler.onChange(newSel);
> >     } else {
> >      super.onSelectionChanged(newSel);
> >     }
> >    }
> >   };
> >   container.add(radioGroupYesNo);
> >   return radioGroupYesNo;
> >  }
> >
> > With the code shown above, the page refreshes, but I want to submit the
> > form and do a page refresh.
> >
> > I don't see where I could associate the form with the RadioChoice?
> >
> > Does RadioChoice need to imlement IFormSubmittingComponent?
> >
> > Berlin Brown
>
>
>
>
public boolean wantOnSelectionChangedNotifica
tions() {
>     return (handler != null); /* When the handler is not null, enable on
> change */
>    }


It was this code.   I didn't add wantOnSelection... to the right
components.  The form was being submitted, some fields weren't getting
saved.



-- 
Berlin Brown (berlin dot brown at gmail.com)
http://botnode.com
http://berlinbrowndev.blogspot.com/