You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Oscar Besga Arcauz <ob...@isdefe.es> on 2013/03/01 16:47:21 UTC

Error with Hidden Field and its enum value

 Hi wickers  !!

I've a problem with a form and a hidden field.
The form has a CompoundPropertyModel of a data class. This class has an enum propertiy, which I want to store into a HiddenField and later retrieve (with the whole data class and the rest of the data).

When the panel is rendered, the hidden field gets the correct value - the enum name() (or toString()? ) value.
But when I retrieve the form, with the AjaxSubmitLink, I get this error in the feedback messagges

    DEBUG - FeedbackMessages           - Adding feedback message '[FeedbackMessage message = "The value of 'myType' is not a valid MyType.", reporter = myType, level = ERROR]'


Any ideas ?

Thanks a lot

 

    > > > Oscar Besga Arcauz  < < < 


EXAMPLE CODE


//Enumerated
public enum MyType { myTypeOne, myTypeTwo, andSoOn }

// Data class
public class MyData implements Serializable {	
	MyType myType;
}

//Panel with form
public class MyPanel extends Panel {

    public MyPanel(String id) {
        super(id);
		MyData data = new MyData();
		data.myType = MyType.myTypeTwo;
        Form<MyData> form = new Form<MyData>("form",new CompoundPropertyModel<MyData>(data));
		form.add(new HiddenField("myType"); //data
        AjaxSubmitLink submit = new AjaxSubmitLink("Submit"){

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                //ALWAYS GETS ME AN ERROR !!! 
				super.onError(target,form);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                super.onSubmit(target, form);
            }
        };		
    }

}


    > > > Oscar Besga Arcauz  < < < 
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Error with Hidden Field and its enum value

Posted by Oscar Besga Arcauz <ob...@isdefe.es>.
Thanks Andrea !!

Yes, I could store the value on the Panel which holds the form - but then I couldn't use it as stateless. Or in WebSession, but it's not adequate...
Also. I could use a String and make the conversion hardcoded..

But I searched the converters, and I tried this (maybe a little complicated) and it worked allright !


    public class MyWebApplication extends WebApplication {

        @Override
        protected IConverterLocator newConverterLocator() {
            ConverterLocator locator = (ConverterLocator) super.newConverterLocator();
            locator.set(MyEnum.class, new MyEnumConverter());
            return locator;
        }

    }


   public class MyEnumConverter implements IConverter<MyEnum> {
   

      @Override
       public MyEnumconvertToObject(String s, Locale locale) {
           try {
                return MyEnum.valueOf(s);
            } catch (Exception e) {
                log_error("MyEnum.valueOf(s) " + s, e);
                return null;
            }
       }

       @Override
       public String convertToString(MyEnum myEnum, Locale locale) {
           return myEnum.name();
       } 
   }

    > > > Oscar Besga Arcauz  < < < 

-----Andrea Del Bene <an...@gmail.com> escribió: -----
Para: users@wicket.apache.org
De: Andrea Del Bene <an...@gmail.com>
Fecha: 01/03/2013  17:55
Asunto: Re: Error with Hidden Field and its enum value

The error occurs because Wicket convert your enum to a string when the 
form is rendered, then it tries to do the opposite converting the string 
to your enum. And here we have the problem. Wicket doesn't fin a valid 
converter (see JAvaDoc of FormComponent.convertInput) to obtain your 
enum from its string value. But the real question is: do you really need 
to have such hidden field in your form? Why can't you simply get rid of it?
>   Hi wickers  !!
>
> I've a problem with a form and a hidden field.
> The form has a CompoundPropertyModel of a data class. This class has an enum propertiy, which I want to store into a HiddenField and later retrieve (with the whole data class and the rest of the data).
>
> When the panel is rendered, the hidden field gets the correct value - the enum name() (or toString()? ) value.
> But when I retrieve the form, with the AjaxSubmitLink, I get this error in the feedback messagges
>
>      DEBUG - FeedbackMessages           - Adding feedback message '[FeedbackMessage message = "The value of 'myType' is not a valid MyType.", reporter = myType, level = ERROR]'
>
>
> Any ideas ?
>
> Thanks a lot
>
>   
>
>      > > > Oscar Besga Arcauz  < < <
>
>
> EXAMPLE CODE
>
>
> //Enumerated
> public enum MyType { myTypeOne, myTypeTwo, andSoOn }
>
> // Data class
> public class MyData implements Serializable {	
> 	MyType myType;
> }
>
> //Panel with form
> public class MyPanel extends Panel {
>
>      public MyPanel(String id) {
>          super(id);
> 		MyData data = new MyData();
> 		data.myType = MyType.myTypeTwo;
>          Form<MyData> form = new Form<MyData>("form",new CompoundPropertyModel<MyData>(data));
> 		form.add(new HiddenField("myType"); //data
>          AjaxSubmitLink submit = new AjaxSubmitLink("Submit"){
>
>              @Override
>              protected void onError(AjaxRequestTarget target, Form<?> form) {
>                  //ALWAYS GETS ME AN ERROR !!!
> 				super.onError(target,form);
>              }
>
>              @Override
>              protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>                  super.onSubmit(target, form);
>              }
>          };		
>      }
>
> }
>
>
>      > > > Oscar Besga Arcauz  < < <
> ---------------------------------------------------------------------
> 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: AjaxSubmitLink.onSubmit() Not Called in FormComponentPanel

Posted by "Richard W. Adams" <RW...@UP.COM>.
Yikes! You're right. OnError() was called instead of onSubmit(). (Hides 
red face & slinks away...)




From:   Sven Meier <sv...@meiers.net>
To:     users@wicket.apache.org
Date:   03/01/2013 12:24 PM
Subject:        Re: AjaxSubmitLink.onSubmit() Not Called in 
FormComponentPanel



Do you have unrendered feedback messages?
Override #onError() and see if it gets invoked.

Sven

On 03/01/2013 06:53 PM, Richard W. Adams wrote:
> I created an AjaxSubmitLink in a FormComponent Panel, and set a break
> point in its onSubmit() method. For some reason, the breakpoint never 
gets
> hit when I click the link. I've used an AjaxSubmitLink on a normal,
> non-panel page successfully, and modeled the panelized link after that, 
so
> am not sure where the problem lies.
>
> Here's the code where I create the link. The non-functioning break point
> is on the System.out.println() statement.
>
> private Component createTrackLookupLink(final Form<?> form) {
>
>          final AjaxSubmitLink link = new AjaxSubmitLink("track-lookup",
> form) {
>                  private static final long serialVersionUID =
> 6256611774949674998L;
>                  @Override protected void onSubmit(final 
AjaxRequestTarget
> target, final Form<?> form) {
>
>                          System.out.println("User clicked lookup icon");
>                  }
>          };
>          link.add(new Icon("track-lookup-icon", IconType.LOOKUP));
>          return link;
> }
>
> I create the link from inside the panel constructor:
>
> public PointLocationPanel(final String id, final
> IModel<PointFacilityLocation> model, final
>          boolean box, final Collapsible collapsible, final boolean
> editable, final Form<?> form) {
>
>          super(id, model);
>          setType(PointFacilityLocation.class);
>          setOutputMarkupId(true);
>          final MarkupContainer container = box ? new Box(CONTAINER_ID,
> "Location", collapsible) :
>                  new WebMarkupContainer(CONTAINER_ID);
>          add(container);
>          ...
>          container.add(createTrackLookupLink(form));
>
> I create the link from inside the panel constructor:
>
>          final PointLocationPanel panel = new PointLocationPanel(
> SWITCH_LOCATION, propertyModel,
>                  true, Collapsible.EXPANDED, userCanEditData, form);
>
>          form.add(panel).add(createDetailsBox());
>
> The enclosing form has its own onSubmit() method. It wouldn't prevent 
the
> link's onSubmit() method from beign called, would it?
>
> When I click the link, I see this output in the Wicket Ajax debug 
window:
>
> INFO: focus set on track_lookup20
> INFO: Using XMLHttpRequest transport
> INFO:
> INFO:
> Initiating Ajax POST request on 
?wicket:interface=:4:switch-form:switchLocation:container:track-lookup::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true&random=0.7709037117446776
> INFO: Invoking pre-call handler(s)...
> INFO: Received ajax response (69 characters)
> INFO:
> <?xml version="1.0" encoding="UTF-8"?><ajax-response></ajax-response>
> INFO: Response parsed. Now invoking steps...
> INFO: Response processed successfully.
> INFO: Invoking post-call handler(s)...
>
> **
>
> This email and any attachments may contain information that is 
confidential and/or privileged for the sole use of the intended recipient. 
 Any use, review, disclosure, copying, distribution or reliance by others, 
and any forwarding of this email or its contents, without the express 
permission of the sender is strictly prohibited by law.  If you are not 
the intended recipient, please contact the sender immediately, delete the 
e-mail and destroy all copies.
> **
>


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




**

This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
**

Re: AjaxSubmitLink.onSubmit() Not Called in FormComponentPanel

Posted by Sven Meier <sv...@meiers.net>.
Do you have unrendered feedback messages?
Override #onError() and see if it gets invoked.

Sven

On 03/01/2013 06:53 PM, Richard W. Adams wrote:
> I created an AjaxSubmitLink in a FormComponent Panel, and set a break
> point in its onSubmit() method. For some reason, the breakpoint never gets
> hit when I click the link. I've used an AjaxSubmitLink on a normal,
> non-panel page successfully, and modeled the panelized link after that, so
> am not sure where the problem lies.
>
> Here's the code where I create the link. The non-functioning break point
> is on the System.out.println() statement.
>
> private Component createTrackLookupLink(final Form<?> form) {
>
>          final AjaxSubmitLink link = new AjaxSubmitLink("track-lookup",
> form) {
>                  private static final long serialVersionUID =
> 6256611774949674998L;
>                  @Override protected void onSubmit(final AjaxRequestTarget
> target, final Form<?> form) {
>
>                          System.out.println("User clicked lookup icon");
>                  }
>          };
>          link.add(new Icon("track-lookup-icon", IconType.LOOKUP));
>          return link;
> }
>
> I create the link from inside the panel constructor:
>
> public PointLocationPanel(final String id, final
> IModel<PointFacilityLocation> model, final
>          boolean box, final Collapsible collapsible, final boolean
> editable, final Form<?> form) {
>
>          super(id, model);
>          setType(PointFacilityLocation.class);
>          setOutputMarkupId(true);
>          final MarkupContainer container = box ? new Box(CONTAINER_ID,
> "Location", collapsible) :
>                  new WebMarkupContainer(CONTAINER_ID);
>          add(container);
>          ...
>          container.add(createTrackLookupLink(form));
>
> I create the link from inside the panel constructor:
>
>          final PointLocationPanel panel = new PointLocationPanel(
> SWITCH_LOCATION, propertyModel,
>                  true, Collapsible.EXPANDED, userCanEditData, form);
>
>          form.add(panel).add(createDetailsBox());
>
> The enclosing form has its own onSubmit() method. It wouldn't prevent the
> link's onSubmit() method from beign called, would it?
>
> When I click the link, I see this output in the Wicket Ajax debug window:
>
> INFO: focus set on track_lookup20
> INFO: Using XMLHttpRequest transport
> INFO:
> INFO:
> Initiating Ajax POST request on ?wicket:interface=:4:switch-form:switchLocation:container:track-lookup::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true&random=0.7709037117446776
> INFO: Invoking pre-call handler(s)...
> INFO: Received ajax response (69 characters)
> INFO:
> <?xml version="1.0" encoding="UTF-8"?><ajax-response></ajax-response>
> INFO: Response parsed. Now invoking steps...
> INFO: Response processed successfully.
> INFO: Invoking post-call handler(s)...
>
> **
>
> This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
> **
>


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


AjaxSubmitLink.onSubmit() Not Called in FormComponentPanel

Posted by "Richard W. Adams" <RW...@UP.COM>.
I created an AjaxSubmitLink in a FormComponent Panel, and set a break 
point in its onSubmit() method. For some reason, the breakpoint never gets 
hit when I click the link. I've used an AjaxSubmitLink on a normal, 
non-panel page successfully, and modeled the panelized link after that, so 
am not sure where the problem lies.

Here's the code where I create the link. The non-functioning break point 
is on the System.out.println() statement.

private Component createTrackLookupLink(final Form<?> form) {

        final AjaxSubmitLink link = new AjaxSubmitLink("track-lookup", 
form) {
                private static final long serialVersionUID = 
6256611774949674998L;
                @Override protected void onSubmit(final AjaxRequestTarget 
target, final Form<?> form) {

                        System.out.println("User clicked lookup icon");
                }
        };
        link.add(new Icon("track-lookup-icon", IconType.LOOKUP));
        return link;
}

I create the link from inside the panel constructor:

public PointLocationPanel(final String id, final 
IModel<PointFacilityLocation> model, final
        boolean box, final Collapsible collapsible, final boolean 
editable, final Form<?> form) {

        super(id, model);
        setType(PointFacilityLocation.class);
        setOutputMarkupId(true); 
        final MarkupContainer container = box ? new Box(CONTAINER_ID, 
"Location", collapsible) :
                new WebMarkupContainer(CONTAINER_ID);
        add(container);
        ...
        container.add(createTrackLookupLink(form));

I create the link from inside the panel constructor:

        final PointLocationPanel panel = new PointLocationPanel(
SWITCH_LOCATION, propertyModel,
                true, Collapsible.EXPANDED, userCanEditData, form);

        form.add(panel).add(createDetailsBox());

The enclosing form has its own onSubmit() method. It wouldn't prevent the 
link's onSubmit() method from beign called, would it?

When I click the link, I see this output in the Wicket Ajax debug window:

INFO: focus set on track_lookup20
INFO: Using XMLHttpRequest transport
INFO: 
INFO: 
Initiating Ajax POST request on ?wicket:interface=:4:switch-form:switchLocation:container:track-lookup::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true&random=0.7709037117446776
INFO: Invoking pre-call handler(s)...
INFO: Received ajax response (69 characters)
INFO: 
<?xml version="1.0" encoding="UTF-8"?><ajax-response></ajax-response>
INFO: Response parsed. Now invoking steps...
INFO: Response processed successfully.
INFO: Invoking post-call handler(s)...

**

This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
**

Re: Error with Hidden Field and its enum value

Posted by Andrea Del Bene <an...@gmail.com>.
The error occurs because Wicket convert your enum to a string when the 
form is rendered, then it tries to do the opposite converting the string 
to your enum. And here we have the problem. Wicket doesn't fin a valid 
converter (see JAvaDoc of FormComponent.convertInput) to obtain your 
enum from its string value. But the real question is: do you really need 
to have such hidden field in your form? Why can't you simply get rid of it?
>   Hi wickers  !!
>
> I've a problem with a form and a hidden field.
> The form has a CompoundPropertyModel of a data class. This class has an enum propertiy, which I want to store into a HiddenField and later retrieve (with the whole data class and the rest of the data).
>
> When the panel is rendered, the hidden field gets the correct value - the enum name() (or toString()? ) value.
> But when I retrieve the form, with the AjaxSubmitLink, I get this error in the feedback messagges
>
>      DEBUG - FeedbackMessages           - Adding feedback message '[FeedbackMessage message = "The value of 'myType' is not a valid MyType.", reporter = myType, level = ERROR]'
>
>
> Any ideas ?
>
> Thanks a lot
>
>   
>
>      > > > Oscar Besga Arcauz  < < <
>
>
> EXAMPLE CODE
>
>
> //Enumerated
> public enum MyType { myTypeOne, myTypeTwo, andSoOn }
>
> // Data class
> public class MyData implements Serializable {	
> 	MyType myType;
> }
>
> //Panel with form
> public class MyPanel extends Panel {
>
>      public MyPanel(String id) {
>          super(id);
> 		MyData data = new MyData();
> 		data.myType = MyType.myTypeTwo;
>          Form<MyData> form = new Form<MyData>("form",new CompoundPropertyModel<MyData>(data));
> 		form.add(new HiddenField("myType"); //data
>          AjaxSubmitLink submit = new AjaxSubmitLink("Submit"){
>
>              @Override
>              protected void onError(AjaxRequestTarget target, Form<?> form) {
>                  //ALWAYS GETS ME AN ERROR !!!
> 				super.onError(target,form);
>              }
>
>              @Override
>              protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>                  super.onSubmit(target, form);
>              }
>          };		
>      }
>
> }
>
>
>      > > > Oscar Besga Arcauz  < < <
> ---------------------------------------------------------------------
> 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