开发者

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

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.

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?


Your problem isn't the connection of the form to the RadioChoice, as most form-handling stuff for form components searches the component hierarchy for a containing form and will find it even if it's not the immediate parent.

But RadioChoice doesn't naturally submit the form, and something likely needs to be done client-side to make an actual form submission occur.

Using wantOnSelectionChangedNotifications just enables javascript for an Ajax request informing the server of the change in the radio selection. This Ajax does not include a form submission.

You might be able to attach a subclass of AjaxFormSubmitBehavior to your RadioChoice and get an actual form submission to happen, but I haven't tried this and don't know if it will work at all.

You might alternatively try attaching an AjaxFormComponentUpdatingBehavior and then refreshing only the portions of the page affected as in this example code (for DropDownChoice, but similar tactics can work for RadioChoice). If the problem is that you're losing changes for other input elements (which aren't known server-side for lack of a submit), this might lead you to a solution of your root problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜