|
I've got a form bound to a CompoundPropertyModel. One of the properties contains a XML document. In order to edit that property, I've added a TextArea to the form (with the CodeMirror javascript XML editor bound to it), but I need to convert the XML document property to string and back again. I've implemented this by creating an anonymous model, like this: lForm.add(new TextArea<>("services", new IModel<String>() { @Override public void detach() { } @Override public String getObject() { return JAXBUtil.extractAndSerializeServicesElement(lLicenseJAXB); } @Override public void setObject(String s) { try { JAXBUtil.parseAndSpliceServicesElement(lLicenseJAXB, s); } catch (Exception e) { lErrorOccurredAtomicBoolean.set(true); slf4j.error("Error during submit", e); error(e.getLocalizedMessage()); } } }).setOutputMarkupId(true).setMarkupId("codemirror")); There are a few question I have: 1. Is this the right way to add such a conversion? 2. Will this model be persisted to the session as well? I of course do not want that, it just needs to convert. 3. If there is an exception in setObject, I use an AtomicBoolean to register that, so that the Form.onSubmit knows that something is amiss. Otherwise I get a big fat exception on the screen or the ssubmit just continues. Is there a better way? 4. If there is an error, I would like getObject to return the value that was submitted by the form, so that the user can correct his mistake. Now it always returns the value before the edit. How to do that? --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Hi,
Use a custom IConverter instead - override TextArea#getConverter(Class) method. Conversion of data is part of form submit process and if it fails with org.apache.wicket.util.convert.ConversionException then the model of that component is not updated and Form#onError() will be called. Point 4) below will be automatically handled for you by Wicket. On Wed, Apr 25, 2012 at 3:18 PM, Tom Eugelink <[hidden email]> wrote: > > I've got a form bound to a CompoundPropertyModel. One of the properties > contains a XML document. In order to edit that property, I've added a > TextArea to the form (with the CodeMirror javascript XML editor bound to > it), but I need to convert the XML document property to string and back > again. I've implemented this by creating an anonymous model, like this: > > lForm.add(new TextArea<>("services", new IModel<String>() > { > @Override > public void detach() > { > } > > @Override > public String getObject() > { > return > JAXBUtil.extractAndSerializeServicesElement(lLicenseJAXB); > } > > @Override > public void setObject(String s) > { > try > { > JAXBUtil.parseAndSpliceServicesElement(lLicenseJAXB, > s); > } > catch (Exception e) > { > lErrorOccurredAtomicBoolean.set(true); > slf4j.error("Error during submit", e); > error(e.getLocalizedMessage()); > } > } > }).setOutputMarkupId(true).setMarkupId("codemirror")); > > There are a few question I have: > 1. Is this the right way to add such a conversion? > 2. Will this model be persisted to the session as well? I of course do not > want that, it just needs to convert. > 3. If there is an exception in setObject, I use an AtomicBoolean to register > that, so that the Form.onSubmit knows that something is amiss. Otherwise I > get a big fat exception on the screen or the ssubmit just continues. Is > there a better way? > 4. If there is an error, I would like getObject to return the value that was > submitted by the form, so that the user can correct his mistake. Now it > always returns the value before the edit. How to do that? > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
The converter correctly converts, but if there is an error in the converter, I'm getting a exception dump on screen. Root cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 3; The element type "notificationx" must be terminated by the matching end-tag "</notificationx>". at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) at com.service2media.licenseframework.service.license.jaxb.JAXBUtil.parseServicesElement(JAXBUtil.java:256) at com.service2media.licenseframework.wicket.MasterLicenseEdit$13$1.convertToObject(MasterLicenseEdit.java:395) at org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1141) at org.apache.wicket.markup.html.form.AbstractTextComponent.convertInput(AbstractTextComponent.java:129) at org.apache.wicket.markup.html.form.FormComponent.validate(FormComponent.java:1083) at org.apache.wicket.markup.html.form.Form$16.validate(Form.java:1759) at org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:170) at org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:154) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:261) at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244) at org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:349) at org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(Form.java:998) at org.apache.wicket.markup.html.form.Form.validateComponents(Form.java:1751) at org.apache.wicket.markup.html.form.Form.validate(Form.java:1716) at org.apache.wicket.markup.html.form.Form.process(Form.java:803) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:241) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722) Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at [ [Component id = form]] on component [ [Component id = form]] threw an exception at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 3; The element type "notificationx" must be terminated by the matching end-tag "</notificationx>". at com.service2media.licenseframework.service.license.jaxb.JAXBUtil.parseServicesElement(JAXBUtil.java:259) at com.service2media.licenseframework.wicket.MasterLicenseEdit$13$1.convertToObject(MasterLicenseEdit.java:395) at org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1141) at org.apache.wicket.markup.html.form.AbstractTextComponent.convertInput(AbstractTextComponent.java:129) at org.apache.wicket.markup.html.form.FormComponent.validate(FormComponent.java:1083) at org.apache.wicket.markup.html.form.Form$16.validate(Form.java:1759) at org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:170) at org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:154) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:261) at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244) at org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:349) at org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(Form.java:998) at org.apache.wicket.markup.html.form.Form.validateComponents(Form.java:1751) at org.apache.wicket.markup.html.form.Form.validate(Form.java:1716) at org.apache.wicket.markup.html.form.Form.process(Form.java:803) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
"... and if it fails with
org.apache.wicket.util.convert.ConversionException ..." try/catch your code and wrap the original exception in ConversionException and rethrow On Wed, Apr 25, 2012 at 3:53 PM, Tom Eugelink <[hidden email]> wrote: > > The converter correctly converts, but if there is an error in the converter, > I'm getting a exception dump on screen. > > Root cause: > > org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 3; The element > type "notificationx" must be terminated by the matching end-tag > "</notificationx>". > at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) > at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) > at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) > at > com.service2media.licenseframework.service.license.jaxb.JAXBUtil.parseServicesElement(JAXBUtil.java:256) > at > com.service2media.licenseframework.wicket.MasterLicenseEdit$13$1.convertToObject(MasterLicenseEdit.java:395) > at > org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1141) > at > org.apache.wicket.markup.html.form.AbstractTextComponent.convertInput(AbstractTextComponent.java:129) > at > org.apache.wicket.markup.html.form.FormComponent.validate(FormComponent.java:1083) > at org.apache.wicket.markup.html.form.Form$16.validate(Form.java:1759) > at > org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:170) > at > org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:154) > at > org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273) > at > org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:261) > at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244) > at > org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:349) > at > org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(Form.java:998) > at > org.apache.wicket.markup.html.form.Form.validateComponents(Form.java:1751) > at org.apache.wicket.markup.html.form.Form.validate(Form.java:1716) > at org.apache.wicket.markup.html.form.Form.process(Form.java:803) > at > org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762) > at > org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692) > at java.lang.reflect.Method.invoke(Method.java:601) > at > org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) > at > org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) > at > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) > at > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) > at > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) > at > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) > at > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) > at > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) > at > org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:241) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) > at > org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) > at > org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) > at > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) > at > org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) > at > com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) > at > com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) > at > com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) > at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) > at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) > at > com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) > at > com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) > at > com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) > at > com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) > at > com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) > at > com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) > at > com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) > at com.sun.grizzly.ContextTask.run(ContextTask.java:71) > at > com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) > at > com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) > at java.lang.Thread.run(Thread.java:722) > > Complete stack: > > org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of > interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at > [ [Component id = form]] on component [ [Component id = form]] threw an > exception > at > org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270) > at > org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) > at > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) > at > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) > at > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) > at > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) > at > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) > at > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) > > java.lang.reflect.InvocationTargetException > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at java.lang.reflect.Method.invoke(Method.java:601) > at > org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) > at > org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) > at > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) > at > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) > at > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) > at > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) > at > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) > at > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) > > java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber: 4; > columnNumber: 3; The element type "notificationx" must be terminated by the > matching end-tag "</notificationx>". > at > com.service2media.licenseframework.service.license.jaxb.JAXBUtil.parseServicesElement(JAXBUtil.java:259) > at > com.service2media.licenseframework.wicket.MasterLicenseEdit$13$1.convertToObject(MasterLicenseEdit.java:395) > at > org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1141) > at > org.apache.wicket.markup.html.form.AbstractTextComponent.convertInput(AbstractTextComponent.java:129) > at > org.apache.wicket.markup.html.form.FormComponent.validate(FormComponent.java:1083) > at org.apache.wicket.markup.html.form.Form$16.validate(Form.java:1759) > at > org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:170) > at > org.apache.wicket.markup.html.form.Form$ValidationVisitor.component(Form.java:154) > at > org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273) > at > org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:261) > at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244) > at > org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:349) > at > org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(Form.java:998) > at > org.apache.wicket.markup.html.form.Form.validateComponents(Form.java:1751) > at org.apache.wicket.markup.html.form.Form.validate(Form.java:1716) > at org.apache.wicket.markup.html.form.Form.process(Form.java:803) > at > org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:762) > at > org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:692) > at java.lang.reflect.Method.invoke(Method.java:601) > at > org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) > at > org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248) > at > org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) > at > org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) > at > org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) > at > org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) > at > org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) > at > org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) > at > org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:185) > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by Martin Grigorov-4
My understanding of this class must be faulty. When Wicket calls my
onSelectionChanged(), the argument is the display string, not the id value. For example, I'm expecting a milepost value like "123.456", but instead I get "End (123.456)" (the display value). Here's the code. can anyone see what I'm doing wrong? private RadioChoice<String> createMilepostChoice(final String id, final TrackModel track) { final Milepost startMP = track.getStartMP(); final Milepost endMP = track.getEndMP (); final List<String> choices = Arrays.asList(new String[]{format(START, startMP), format(END, endMP), OTHER}); final ChoiceRenderer<String> renderer = new ChoiceRenderer<String>() { private static final long serialVersionUID = 1L; @Override public Object getDisplayValue(final String model) { return model; } @Override public String getIdValue(final String model, final int index) { String value; switch (index) { case 0: value = startMP.toString(); break; case 1 : value = endMP.toString(); break; default : value = ""; } return value; } }; final RadioChoice<String> choice = new RadioChoice<String>(id, choices, renderer) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(final Object new selection) { final String selection = (String)newSelection; if (track == primaryTrack) { primaryMpChoice = selection; } else { secondaryMpChoice = selection; } } @Override protected boolean wantOnSelectionChangedNotifications() { return true; } }; return choice; } ** 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. ** |
|
In reply to this post by Martin Grigorov-4
You are right. I'm sorry. On 25-4-2012 14:56, Martin Grigorov wrote: > "... and if it fails with > org.apache.wicket.util.convert.ConversionException ..." > > try/catch your code and wrap the original exception in > ConversionException and rethrow > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
In reply to this post by aksarben
>When Wicket calls my onSelectionChanged(), the argument is the display
string, not the id value. Your RadioChoice is working on string choices so it will hand you the selected string. I'd suggest to let your RadioChoice work with ints or preferably directly on the Milepost objects: final RadioChoice<Milepost> choice = new RadioChoice<Milepost>(...); Sven On 04/25/2012 03:00 PM, Richard W. Adams wrote: > My understanding of this class must be faulty. When Wicket calls my > onSelectionChanged(), the argument is the display string, not the id > value. For example, I'm expecting a milepost value like "123.456", but > instead I get "End (123.456)" (the display value). Here's the code. can > anyone see what I'm doing wrong? > > private RadioChoice<String> createMilepostChoice(final String id, final > TrackModel track) { > > final Milepost startMP = track.getStartMP(); > final Milepost endMP = track.getEndMP (); > final List<String> choices = Arrays.asList(new > String[]{format(START, startMP), format(END, endMP), OTHER}); > final ChoiceRenderer<String> renderer = new > ChoiceRenderer<String>() { > private static final long serialVersionUID = 1L; > @Override public Object getDisplayValue(final String model) { > return model; > } > @Override public String getIdValue(final String model, final int > index) { > String value; > switch (index) { > case 0: > value = startMP.toString(); > break; > case 1 : > value = endMP.toString(); > break; > default : > value = ""; > } > return value; > } > }; > final RadioChoice<String> choice = new RadioChoice<String>(id, > choices, renderer) { > private static final long serialVersionUID = 1L; > @Override protected void onSelectionChanged(final Object > new selection) { > final String selection = (String)newSelection; > if (track == primaryTrack) { > primaryMpChoice = selection; > } else { > secondaryMpChoice = selection; > } > } > @Override protected boolean > wantOnSelectionChangedNotifications() { > return true; > } > }; > return choice; > } > > > ** > > 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: [hidden email] For additional commands, e-mail: [hidden email] |
|
Ok, I tried changing it to RadioChoice<MilepostModel> (code below).
However, the onSelectionChanged() method STILL gets a String argument, as verified by the printf() output "New selection is a class java.lang.String: End (538.200)." But following that output, an exception is now thrown. I REALLY don't understand what's going on here. I've studied the Javadocs for RadioChoice, but they seem awfully sketchy, and don't shed any light on this. Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.uprr.enm.web.track.mend.MilepostModel at com.uprr.enm.web.track.mend.MendStepChooseMP$4.getIdValue( MendStepChooseMP.java:1) at org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.getModelValue( AbstractSingleSelectChoice.java:166) at org.apache.wicket.markup.html.form.FormComponent.getValue( FormComponent.java:911) at org.apache.wicket.markup.html.form.RadioChoice.onComponentTagBody( RadioChoice.java:422) at org.apache.wicket.Component.renderComponent(Component.java:2725 ) ... 198 more ================================================================== //---------------------------------------------------------------------------------------------- private RadioChoice<MilepostModel> createTestChoice(final String id, final TrackModel track) { final List<MilepostModel> choices = new ArrayList<MilepostModel>(); choices.add(new MilepostModel(track.getStartMP(), "Start")); choices.add(new MilepostModel(track.getEndMP(), "End")); choices.add(new MilepostModel("Other")); final ChoiceRenderer<MilepostModel> renderer = new ChoiceRenderer<MilepostModel>() { private static final long serialVersionUID = 1L; @Override public String getIdValue(final MilepostModel model, final int index) { final Milepost mp = model.getObject(); return mp == null ? "" : mp.toString(); } }; final RadioChoice<MilepostModel> choice = new RadioChoice<MilepostModel>(id, choices, renderer) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(final Object newSelection) { System.out.printf("New selection is a %s: %s%n", newSelection.getClass(), newSelection); } @Override protected boolean wantOnSelectionChangedNotifications() { return true; } }; return choice; } The milepost model class: package com.uprr.enm.web.track.mend; import org.apache.wicket.model.IModel; import com.uprr.eni.read.vo.mp.Milepost; //---------------------------------------------------------------------------------------------- /** * Data model for milepost values. * @author Dick Adams * @.copyright Union Pacific 2012 */ class MilepostModel implements IModel<Milepost> { private static final long serialVersionUID = 1L; private final String text; private Milepost mp; //---------------------------------------------------------------------------------------------- /** * Constructor. * @param value The milepost value. * @param text The textual description of the value. For example, if it represents the end * of a milepost range, the text might be {@code End}. */ public MilepostModel(final Milepost value, final String text) { mp = value; this.text = text; } //---------------------------------------------------------------------------------------------- /** * Constructor with no value. * @param text The textual description of a {@code null} value. */ public MilepostModel(final String text) { this(null, text); } //---------------------------------------------------------------------------------------------- @Override public void detach() { mp = null; } //---------------------------------------------------------------------------------------------- @Override public Milepost getObject() { return mp; } //---------------------------------------------------------------------------------------------- @Override public void setObject(final Milepost object) { mp = object; } //---------------------------------------------------------------------------------------------- @Override public String toString() { return mp == null ? text : String.format("%s (%s)", text, mp.toString()); } //---------------------------------------------------------------------------------------------- } From: Sven Meier <[hidden email]> To: [hidden email] Date: 04/25/2012 09:55 AM Subject: Re: Radio Choice Weirdness >When Wicket calls my onSelectionChanged(), the argument is the display string, not the id value. Your RadioChoice is working on string choices so it will hand you the selected string. I'd suggest to let your RadioChoice work with ints or preferably directly on the Milepost objects: final RadioChoice<Milepost> choice = new RadioChoice<Milepost>(...); Sven On 04/25/2012 03:00 PM, Richard W. Adams wrote: > My understanding of this class must be faulty. When Wicket calls my > onSelectionChanged(), the argument is the display string, not the id > value. For example, I'm expecting a milepost value like "123.456", but > instead I get "End (123.456)" (the display value). Here's the code. can > anyone see what I'm doing wrong? > > private RadioChoice<String> createMilepostChoice(final String id, final > TrackModel track) { > > final Milepost startMP = track.getStartMP(); > final Milepost endMP = track.getEndMP (); > final List<String> choices = Arrays.asList(new > String[]{format(START, startMP), format(END, endMP), OTHER}); > final ChoiceRenderer<String> renderer = new > ChoiceRenderer<String>() { > private static final long serialVersionUID = 1L; > @Override public Object getDisplayValue(final String model) { > return model; > } > @Override public String getIdValue(final String model, final > index) { > String value; > switch (index) { > case 0: > value = startMP.toString(); > break; > case 1 : > value = endMP.toString(); > break; > default : > value = ""; > } > return value; > } > }; > final RadioChoice<String> choice = new RadioChoice<String>(id, > choices, renderer) { > private static final long serialVersionUID = 1L; > @Override protected void onSelectionChanged(final > new selection) { > final String selection = (String)newSelection; > if (track == primaryTrack) { > primaryMpChoice = selection; > } else { > secondaryMpChoice = selection; > } > } > @Override protected boolean > wantOnSelectionChangedNotifications() { > return true; > } > }; > return choice; > } > > > ** > > This email and any attachments may contain information that is 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: [hidden email] For additional commands, e-mail: [hidden email] ** 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. ** |
|
Oops. Got it figured out. The page class was trying to store the choice in
a String variable instead of a MilepostModel variable. All is well now. Thanks! "RAM /abr./: Rarely Adequate Memory." From: "Richard W. Adams" <[hidden email]> To: [hidden email] Cc: [hidden email] Date: 04/25/2012 10:24 AM Subject: Re: Radio Choice Weirdness Ok, I tried changing it to RadioChoice<MilepostModel> (code below). However, the onSelectionChanged() method STILL gets a String argument, as verified by the printf() output "New selection is a class java.lang.String: End (538.200)." But following that output, an exception is now thrown. I REALLY don't understand what's going on here. I've studied the Javadocs for RadioChoice, but they seem awfully sketchy, and don't shed any light on this. Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.uprr.enm.web.track.mend.MilepostModel at com.uprr.enm.web.track.mend.MendStepChooseMP$4.getIdValue( MendStepChooseMP.java:1) at org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.getModelValue( AbstractSingleSelectChoice.java:166) at org.apache.wicket.markup.html.form.FormComponent.getValue( FormComponent.java:911) at org.apache.wicket.markup.html.form.RadioChoice.onComponentTagBody( RadioChoice.java:422) at org.apache.wicket.Component.renderComponent(Component.java:2725 ) ... 198 more ================================================================== //---------------------------------------------------------------------------------------------- private RadioChoice<MilepostModel> createTestChoice(final String id, final TrackModel track) { final List<MilepostModel> choices = new ArrayList<MilepostModel>(); choices.add(new MilepostModel(track.getStartMP(), "Start")); choices.add(new MilepostModel(track.getEndMP(), "End")); choices.add(new MilepostModel("Other")); final ChoiceRenderer<MilepostModel> renderer = new ChoiceRenderer<MilepostModel>() { private static final long serialVersionUID = 1L; @Override public String getIdValue(final MilepostModel model, final int index) { final Milepost mp = model.getObject(); return mp == null ? "" : mp.toString(); } }; final RadioChoice<MilepostModel> choice = new RadioChoice<MilepostModel>(id, choices, renderer) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(final Object newSelection) { System.out.printf("New selection is a %s: %s%n", newSelection.getClass(), newSelection); } @Override protected boolean wantOnSelectionChangedNotifications() { return true; } }; return choice; } The milepost model class: package com.uprr.enm.web.track.mend; import org.apache.wicket.model.IModel; import com.uprr.eni.read.vo.mp.Milepost; //---------------------------------------------------------------------------------------------- /** * Data model for milepost values. * @author Dick Adams * @.copyright Union Pacific 2012 */ class MilepostModel implements IModel<Milepost> { private static final long serialVersionUID = 1L; private final String text; private Milepost mp; //---------------------------------------------------------------------------------------------- /** * Constructor. * @param value The milepost value. * @param text The textual description of the value. For example, if it represents the end * of a milepost range, the text might be {@code End}. */ public MilepostModel(final Milepost value, final String text) { mp = value; this.text = text; } //---------------------------------------------------------------------------------------------- /** * Constructor with no value. * @param text The textual description of a {@code null} value. */ public MilepostModel(final String text) { this(null, text); } //---------------------------------------------------------------------------------------------- @Override public void detach() { mp = null; } //---------------------------------------------------------------------------------------------- @Override public Milepost getObject() { return mp; } //---------------------------------------------------------------------------------------------- @Override public void setObject(final Milepost object) { mp = object; } //---------------------------------------------------------------------------------------------- @Override public String toString() { return mp == null ? text : String.format("%s (%s)", text, mp.toString()); } //---------------------------------------------------------------------------------------------- } From: Sven Meier <[hidden email]> To: [hidden email] Date: 04/25/2012 09:55 AM Subject: Re: Radio Choice Weirdness >When Wicket calls my onSelectionChanged(), the argument is the display string, not the id value. Your RadioChoice is working on string choices so it will hand you the selected string. I'd suggest to let your RadioChoice work with ints or preferably directly on the Milepost objects: final RadioChoice<Milepost> choice = new RadioChoice<Milepost>(...); Sven On 04/25/2012 03:00 PM, Richard W. Adams wrote: > My understanding of this class must be faulty. When Wicket calls my > onSelectionChanged(), the argument is the display string, not the id > value. For example, I'm expecting a milepost value like "123.456", but > instead I get "End (123.456)" (the display value). Here's the code. can > anyone see what I'm doing wrong? > > private RadioChoice<String> createMilepostChoice(final String id, final > TrackModel track) { > > final Milepost startMP = track.getStartMP(); > final Milepost endMP = track.getEndMP (); > final List<String> choices = Arrays.asList(new > String[]{format(START, startMP), format(END, endMP), OTHER}); > final ChoiceRenderer<String> renderer = new > ChoiceRenderer<String>() { > private static final long serialVersionUID = 1L; > @Override public Object getDisplayValue(final String model) { > return model; > } > @Override public String getIdValue(final String model, final > index) { > String value; > switch (index) { > case 0: > value = startMP.toString(); > break; > case 1 : > value = endMP.toString(); > break; > default : > value = ""; > } > return value; > } > }; > final RadioChoice<String> choice = new RadioChoice<String>(id, > choices, renderer) { > private static final long serialVersionUID = 1L; > @Override protected void onSelectionChanged(final > new selection) { > final String selection = (String)newSelection; > if (track == primaryTrack) { > primaryMpChoice = selection; > } else { > secondaryMpChoice = selection; > } > } > @Override protected boolean > wantOnSelectionChangedNotifications() { > return true; > } > }; > return choice; > } > > > ** > > This email and any attachments may contain information that is 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: [hidden email] For additional commands, e-mail: [hidden email] ** 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. ** ** 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. ** |
| Powered by Nabble | Edit this page |
