Re: upload file content to textarea
You could ajax update the textarea after upload, with the content that you want? If you do not want to set the model object then you will have to fake raw input (reflection). ** Martin 2009/9/16 Sam Zilverberg samzilverb...@gmail.com: In one of my wizard's steps I have a upload form and a textarea. The textarea is used to enter serial numbers(seperated by newline) and is connected to a object property of type SetString using a propertymodel. I've written a custom converter to turn the entered input to a SetString and from a SetString back to simple string. When pressing the wizard's next the input is validated and if valid the backing model will have SetString of serials. I want the upload form to be used to upload a file containing serial numbers. I would like that the content of the uploaded file will be placed into the textarea, so that when Next is pressed again it is validated. Is this possible? Can I put the file's content into the text area by pressing upload without ruining the property model the textarea uses? - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: upload file content to textarea
sounds good, but how do I do this? :) On Wed, Sep 16, 2009 at 9:45 PM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: You could ajax update the textarea after upload, with the content that you want? If you do not want to set the model object then you will have to fake raw input (reflection). ** Martin
Re: upload file content to textarea
1. You know how to upload file? http://www.wicket-library.com/wicket-examples/upload/single - or ajax upload http://blog.demay-fr.net/index.php/2007/12/07/93-simulate-ajax-file-upload-with-wicket 2. Just put the file contents into textarea with jafa reflection. 3. AJax update the textarea: http://www.wicket-library.com/wicket-examples/ajax/clock.2 - This is timed update..but similarly just add the textarea into ajax target. ** Martin 2009/9/16 Sam Zilverberg samzilverb...@gmail.com: sounds good, but how do I do this? :) On Wed, Sep 16, 2009 at 9:45 PM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: You could ajax update the textarea after upload, with the content that you want? If you do not want to set the model object then you will have to fake raw input (reflection). ** Martin - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: upload file content to textarea
thanks a lot for the help and the links! I checked them all out, the second one (upload panel) was too complicated for me atm. Maybe I'l come back to it when I'l have more experience with wicket. I liked the timed ajax behaviour example, but couldn't figure out exactly how it works so i could use it in my project. ??how does the behaviour know how to update the clock?? I currently solved this problem by filtering the input from the uploaded file and creating a correct object model (SetString) out of it, then setting the modelObject of the textarea to be this filtered one. I also didn't understand what you meant by simply using reflection to put the content of the file into the textarea, did you mean simply using setModelObject( (SetString) uploadedContent) ? thanks again for all the help so far On Wed, Sep 16, 2009 at 11:32 PM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: 1. You know how to upload file? http://www.wicket-library.com/wicket-examples/upload/single - or ajax upload http://blog.demay-fr.net/index.php/2007/12/07/93-simulate-ajax-file-upload-with-wicket 2. Just put the file contents into textarea with jafa reflection. 3. AJax update the textarea: http://www.wicket-library.com/wicket-examples/ajax/clock.2 - This is timed update..but similarly just add the textarea into ajax target. ** Martin
Re: upload file content to textarea
Hi! I currently solved this problem by filtering the input from the uploaded file and creating a correct object model (SetString) out of it, then setting the modelObject of the textarea to be this filtered one. Good, so you got the upload part working. By reflection I mean that instead of setting model object you could do this, if necessary: public static T extends FormComponent? void fakeRawInput(T formComponent, T existingComponent) { try { String rawInput = (String) rawInputField.get(existingComponent); fakeRawInput(formComponent, rawInput); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } In this way your modelObject state does not change as compared to: simply using setModelObject( (SetString) uploadedContent) ? But if you can change the model that's definitely cleaner. ** Martin On Wed, Sep 16, 2009 at 11:32 PM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: 1. You know how to upload file? http://www.wicket-library.com/wicket-examples/upload/single - or ajax upload http://blog.demay-fr.net/index.php/2007/12/07/93-simulate-ajax-file-upload-with-wicket 2. Just put the file contents into textarea with jafa reflection. 3. AJax update the textarea: http://www.wicket-library.com/wicket-examples/ajax/clock.2 - This is timed update..but similarly just add the textarea into ajax target. ** Martin - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: upload file content to textarea
Ah.. forgot that crucial part, the reflection: public static T extends FormComponent? void fakeRawInput(T formComponent, String value) { try { rawInputField.set(formComponent, value); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } where rawInputField = FormComponent.class.getDeclaredField(rawInput); rawInputField.setAccessible(true); 2009/9/17 Martin Makundi martin.maku...@koodaripalvelut.com: Hi! I currently solved this problem by filtering the input from the uploaded file and creating a correct object model (SetString) out of it, then setting the modelObject of the textarea to be this filtered one. Good, so you got the upload part working. By reflection I mean that instead of setting model object you could do this, if necessary: public static T extends FormComponent? void fakeRawInput(T formComponent, T existingComponent) { try { String rawInput = (String) rawInputField.get(existingComponent); fakeRawInput(formComponent, rawInput); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } In this way your modelObject state does not change as compared to: simply using setModelObject( (SetString) uploadedContent) ? But if you can change the model that's definitely cleaner. ** Martin On Wed, Sep 16, 2009 at 11:32 PM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: 1. You know how to upload file? http://www.wicket-library.com/wicket-examples/upload/single - or ajax upload http://blog.demay-fr.net/index.php/2007/12/07/93-simulate-ajax-file-upload-with-wicket 2. Just put the file contents into textarea with jafa reflection. 3. AJax update the textarea: http://www.wicket-library.com/wicket-examples/ajax/clock.2 - This is timed update..but similarly just add the textarea into ajax target. ** Martin - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: upload file content to textarea
I'd rather use some other method than mine, because with mine the validation of input is done twice when uploading. first on the uploaded file, and then another time on the textarea when pressing the wizard's next button. I tried replacing my fixup with this one but got a big fat java.lang.NoSuchFieldException on getDeclaredField( name) line in the code. I got this a couple of times using different names such as TextArea.class.getSimpleName() and serials (the wicket id for the textarea). Any ideas on what name I should be using? heres some code and the markup for the wizard page with the upload form/textarea : wicket:panel table tr td form wicket:id=simpleUpload fieldset label for=uploadFile/label input wicket:id=fileInput id=upload type=file / button wicket:id=uploadButton span wicket:id=uploadLabelupload/span/button /fieldset /form /td td wicket:message key=serials.textareaInfoinfo message/wicket:message br/ textarea wicket:id=serials/textarea /td /tr /table i'm using button wicket:id=uploadButton in the markup instead of input type=submit as per the example because pressing the latter button causes the whole wizard page to validate, including the text area which is usualy empty in the case of file upload. Button uploadButton = new Button(uploadButton) { @Override public void onSubmit() { final FileUpload upload = fileUploadField.getFileUpload(); if (upload != null) { String uploadedContent = new String(upload.getBytes()); try { Field f = FormComponent.class.getDeclaredField(TextArea.class.getSimpleName()); f.setAccessible(true); f.set(textArea, uploadedContent); } catch (Exception e) { e.printStackTrace(); } } } } On Thu, Sep 17, 2009 at 12:29 AM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: Ah.. forgot that crucial part, the reflection: public static T extends FormComponent? void fakeRawInput(T formComponent, String value) { try { rawInputField.set(formComponent, value); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } where rawInputField = FormComponent.class.getDeclaredField(rawInput); rawInputField.setAccessible(true); 2009/9/17 Martin Makundi martin.maku...@koodaripalvelut.com: Hi! I currently solved this problem by filtering the input from the uploaded file and creating a correct object model (SetString) out of it, then setting the modelObject of the textarea to be this filtered one. Good, so you got the upload part working. By reflection I mean that instead of setting model object you could do this, if necessary: public static T extends FormComponent? void fakeRawInput(T formComponent, T existingComponent) { try { String rawInput = (String) rawInputField.get(existingComponent); fakeRawInput(formComponent, rawInput); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } In this way your modelObject state does not change as compared to: simply using setModelObject( (SetString) uploadedContent) ? But if you can change the model that's definitely cleaner. ** Martin
Re: upload file content to textarea
No.. the field name is rawInput: rawInputField = FormComponent.class.getDeclaredField(rawInput); ** Martin 2009/9/17 Sam Zilverberg samzilverb...@gmail.com: I'd rather use some other method than mine, because with mine the validation of input is done twice when uploading. first on the uploaded file, and then another time on the textarea when pressing the wizard's next button. I tried replacing my fixup with this one but got a big fat java.lang.NoSuchFieldException on getDeclaredField( name) line in the code. I got this a couple of times using different names such as TextArea.class.getSimpleName() and serials (the wicket id for the textarea). Any ideas on what name I should be using? heres some code and the markup for the wizard page with the upload form/textarea : wicket:panel table tr td form wicket:id=simpleUpload fieldset label for=uploadFile/label input wicket:id=fileInput id=upload type=file / button wicket:id=uploadButton span wicket:id=uploadLabelupload/span/button /fieldset /form /td td wicket:message key=serials.textareaInfoinfo message/wicket:message br/ textarea wicket:id=serials/textarea /td /tr /table i'm using button wicket:id=uploadButton in the markup instead of input type=submit as per the example because pressing the latter button causes the whole wizard page to validate, including the text area which is usualy empty in the case of file upload. Button uploadButton = new Button(uploadButton) { �...@override public void onSubmit() { final FileUpload upload = fileUploadField.getFileUpload(); if (upload != null) { String uploadedContent = new String(upload.getBytes()); try { Field f = FormComponent.class.getDeclaredField(TextArea.class.getSimpleName()); f.setAccessible(true); f.set(textArea, uploadedContent); } catch (Exception e) { e.printStackTrace(); } } } } On Thu, Sep 17, 2009 at 12:29 AM, Martin Makundi martin.maku...@koodaripalvelut.com wrote: Ah.. forgot that crucial part, the reflection: public static T extends FormComponent? void fakeRawInput(T formComponent, String value) { try { rawInputField.set(formComponent, value); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } where rawInputField = FormComponent.class.getDeclaredField(rawInput); rawInputField.setAccessible(true); 2009/9/17 Martin Makundi martin.maku...@koodaripalvelut.com: Hi! I currently solved this problem by filtering the input from the uploaded file and creating a correct object model (SetString) out of it, then setting the modelObject of the textarea to be this filtered one. Good, so you got the upload part working. By reflection I mean that instead of setting model object you could do this, if necessary: public static T extends FormComponent? void fakeRawInput(T formComponent, T existingComponent) { try { String rawInput = (String) rawInputField.get(existingComponent); fakeRawInput(formComponent, rawInput); } catch (Exception e) { Utils.errorLog(MarkupUtils.class, Fatal Error: Form field access failed., e); } } In this way your modelObject state does not change as compared to: simply using setModelObject( (SetString) uploadedContent) ? But if you can change the model that's definitely cleaner. ** Martin - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org