Johan,

I got it working as below. Shall I create a Jira issue for this? I think 
it would be more logical if checkbox could deal with cleared input.

     Erik.


        // The reset button
        Button resetButton = new Button("resetbutton") {
            /** [EMAIL PROTECTED] */
            protected void onSubmit() {
                // Clear the form
                form.visitChildren(FormComponent.class, new 
Component.IVisitor() {
                    public Object component(Component component) {
                        FormComponent formComponent = ((FormComponent) 
component);
                        if (formComponent instanceof CheckBox) {
                            ((CheckBox) 
formComponent).setModelObject("false");
                        } else {
                            formComponent.clearInput();
                            formComponent.updateModel();
                        }
                        return 
Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                    }
                });
            }
        };
        // Perform only the onSubmit, no validation
        resetButton.setDefaultFormProcessing(false);
        form.add(resetButton);



Erik van Oosten wrote:
> Yes, correct. The model should be cleared as well.
> And it indeed uses setDefaultFormProcessing(false).
>
> The approach your describing below will throw exceptions for checkboxes:
>
> WicketMessage: unable to set object null, model: 
> Model:classname=[wicket.model.PropertyModel]:attached=true:[EMAIL 
> PROTECTED]:expression=[searchInHistoricNames]:propertyType=[null], 
> called with component [MarkupContainer [Component id = formelement, page 
> = nl.amsterdam.rbrb.web.search.SearchPage, path = 
> 2:maincontent:searchform:form:formElements:2:inputfragment:formelement.CheckBox,
>  
> isVisible = true, isVersioned = false]]
>
> Root cause:
>
> wicket.util.convert.ConversionException: Can't convert null value to a 
> primitive class: boolean for setting it on 
> [EMAIL PROTECTED]
> at 
> wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(Ljava.lang.Object;Ljava.lang.Object;Lwicket.util.convert.IConverter;)V(PropertyResolver.java:838)
> at 
> wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(Ljava.lang.Object;Lwicket.util.convert.IConverter;)V(PropertyResolver.java:447)
> at 
> wicket.util.lang.PropertyResolver.setValue(Ljava.lang.String;Ljava.lang.Object;Ljava.lang.Object;Lwicket.util.convert.IConverter;)V(PropertyResolver.java:136)
> at 
> wicket.model.AbstractPropertyModel.onSetObject(Lwicket.Component;Ljava.lang.Object;)V(AbstractPropertyModel.java:182)
> at 
> wicket.model.AbstractDetachableModel.setObject(Lwicket.Component;Ljava.lang.Object;)V(AbstractDetachableModel.java:131)
> at 
> wicket.Component.setModelObject(Ljava.lang.Object;)Lwicket.Component;(Component.java:2042)
> at 
> wicket.markup.html.form.FormComponent.updateModel()V(FormComponent.java:840)
> at 
> nl.amsterdam.rbrb.web.form.FormPanel$5.component(Lwicket.Component;)Ljava.lang.Object;(FormPanel.java:214)
>    
> <--- the line with formComponent.updateModel();
>
>
> Regards,
>      Erik.
>
>
>
>
> Johan Compagner wrote:
>   
>> why do you want to call updateFormComponentModels?
>> You also want to clear all model data? So the models already did get 
>> some data from a previous request?
>> (i take the reset button has setDefaultFormProcessing(false) ?)
>>
>> but why not do this:
>>
>>  form.visitChildren(FormComponent.class, new
>> Component.IVisitor() {
>>                     public Object component(Component component) {
>>                         ((FormComponent) component).clearInput();
>>                         ((FormComponent) component).updateModel();
>>                         return
>> Component.IVisitor.CONTINUE
>>
>>     _TRAVERSAL_BUT_DONT_GO_DEEPER;
>>                         }
>>                     });
>>
>>
>> On 1/9/07, *Erik van Oosten* < [EMAIL PROTECTED] 
>> <mailto:[EMAIL PROTECTED]>> wrote:
>>
>>     Hi,
>>
>>     I am trying the make a reset button (clears all fields) with code
>>     below.
>>     According to the class comment of Form I can call
>>     updateFormComponentModels, however that method is not visible.
>>
>>     What can I do to get the desired effect? I am using wicket-1.2.4.
>>
>>     Regards,
>>          Erik.
>>
>>
>>             // The reset button
>>             Button resetButton = new Button("resetbutton") {
>>                 /** [EMAIL PROTECTED] */
>>                 protected void onSubmit() {
>>                     // Clear the form
>>                     form.visitChildren(FormComponent.class, new
>>     Component.IVisitor() {
>>                         public Object component(Component component) {
>>                             ((FormComponent) component).clearInput();
>>                             return
>>     Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
>>                         }
>>                     });
>>     *                form.updateFormComponentModels();   // <------ method
>>     not visible
>>     *            }
>>             };
>>             // Perform only the onSubmit, no validation
>>             resetButton.setDefaultFormProcessing(false);
>>             form.add(resetButton);
>>
>>
>>
>>     --
>>     Erik van Oosten
>>     http://www.day-to-day-stuff.blogspot.com/
>>
>>
>>     -------------------------------------------------------------------------
>>     Take Surveys. Earn Cash. Influence the Future of IT
>>     Join SourceForge.net's Techsay panel and you'll get the chance to
>>     share your
>>     opinions on IT & business topics through brief surveys - and earn cash
>>     http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>     
>> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>
>>     _______________________________________________
>>     Wicket-user mailing list
>>     Wicket-user@lists.sourceforge.net
>>     <mailto:Wicket-user@lists.sourceforge.net>
>>     https://lists.sourceforge.net/lists/listinfo/wicket-user
>>
>>
>> ------------------------------------------------------------------------
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share your
>> opinions on IT & business topics through brief surveys - and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Wicket-user mailing list
>> Wicket-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>   
>>     
>
>   

-- 
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to