Re: FileUploadField with AJAX Behavior
I use this home brew Behavior: import java.io.File; import org.apache.wicket.Component; import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.markup.head.OnDomReadyHeaderItem; import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.http.WebRequest; import org.apache.wicket.util.string.StringValue; public abstract class FileSelectedBehavior extends AbstractDefaultAjaxBehavior { public static final String FILE_SELECTED_REQUEST_PARAMETER_NAME = "val"; @Override public void respond( AjaxRequestTarget target ) { // get the web request RequestCycle cycle = RequestCycle.get(); WebRequest webRequest = (WebRequest) cycle.getRequest(); // get the parameter StringValue term = webRequest.getQueryParameters().getParameterValue( FILE_SELECTED_REQUEST_PARAMETER_NAME ); // term contains full (fake) path File file = new File( term.toString() ); // process the parameter this.processRequest( target, file.getName() ); } /** * This method will be called when a file is selected. * * @param target * @param fileName will contain the filename with extension (without path) */ public abstract void processRequest( AjaxRequestTarget target, String fileName ); @Override public void renderHead( Component component, IHeaderResponse response ) { // after selecting a file the onRequest of this class is called String script = "document.getElementById('" + component.getMarkupId() + "').onchange = function () { Wicket.Ajax.get({ 'u' : \"" + this.getCallbackUrl() + "\", 'ep' : {'" + FILE_SELECTED_REQUEST_PARAMETER_NAME + "' : this.value } });};"; // add the javascript response.render( OnDomReadyHeaderItem.forScript( script ) ); } } On Thu, Aug 24, 2017 at 9:57 AM, lucast <lucastol...@hotmail.com> wrote: > I had the same requirement,I wanted to display the contents of the file, > once > the file has been selected. > I found the code on > https://github.com/apache/openmeetings/blob/4a5e859f886253086e51a2ac26bbc5 > 01d621e590/openmeetings-web/src/main/java/org/apache/ > openmeetings/web/common/UploadableImagePanel.java > <https://github.com/apache/openmeetings/blob/ > 4a5e859f886253086e51a2ac26bbc501d621e590/openmeetings-web/ > src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java > > > , line 77, new AjaxFormSubmitBehavior(form, "change") to be extremely > helpful and just what I was looking for. > > > > > -- > View this message in context: http://apache-wicket.1842946. > n4.nabble.com/FileUploadField-with-AJAX-Behavior-tp4677874p4678594.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: FileUploadField with AJAX Behavior
I had the same requirement,I wanted to display the contents of the file, once the file has been selected. I found the code on https://github.com/apache/openmeetings/blob/4a5e859f886253086e51a2ac26bbc501d621e590/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java <https://github.com/apache/openmeetings/blob/4a5e859f886253086e51a2ac26bbc501d621e590/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java> , line 77, new AjaxFormSubmitBehavior(form, "change") to be extremely helpful and just what I was looking for. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/FileUploadField-with-AJAX-Behavior-tp4677874p4678594.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: FileUploadField with AJAX Behavior
We are using: http://www.jasny.net/bootstrap/javascript/#fileinput integrated into our application [1] Looks good, works as expected :) [1] https://github.com/apache/openmeetings/tree/master/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/upload On Fri, May 19, 2017 at 5:57 AM, Martin Grigorov <mgrigo...@apache.org> wrote: > Hi, > > Please create a quickstart app and attach it to a ticket in JIRA! > Thanks! > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Tue, May 16, 2017 at 6:35 PM, SeldonCrisis <nmbara...@gmail.com> wrote: > >> Hello everyone, >> >> I would like to perform some actions in an AJAX event after selecting a >> file >> from the file-browsing pop-up window in a FileUploadField component >> (populate a list based on name of file chosen). I've tried adding an >> OnChangeAjaxBehavior to my FileUploadField and implementing the >> onUpdate(AjaxRequestTarget arg0) method. Unfortunately, this is not working >> for me. Does anyone have any suggestions as to how I could AJAX-ify this >> component? >> >> This is my current code: >> >> fileUploadField.add(new OnChangeAjaxBehavior(){ >> private static final long serialVersionUID = 1L; >> >> @Override >> protected void onUpdate(AjaxRequestTarget arg0) { >> if (fileUploadField.getFileUpload() != null){ >> info("Added file to list"); >> final FileUpload uploadedFile = >> fileUploadField.getFileUpload(); >> addFile(uploadedFile); >> buildListView(); >> arg0.add(fileUploadField); >> arg0.add(documentListItems); >> arg0.add(feedback); >> } >> } >> }); >> >> Thanks for your help! >> >> >> -- >> View this message in context: http://apache-wicket.1842946. >> n4.nabble.com/FileUploadField-with-AJAX-Behavior-tp4677874.html >> Sent from the Users forum mailing list archive at Nabble.com. >> >> - >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> -- WBR Maxim aka solomax - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: FileUploadField with AJAX Behavior
Hi, Please create a quickstart app and attach it to a ticket in JIRA! Thanks! Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Tue, May 16, 2017 at 6:35 PM, SeldonCrisis <nmbara...@gmail.com> wrote: > Hello everyone, > > I would like to perform some actions in an AJAX event after selecting a > file > from the file-browsing pop-up window in a FileUploadField component > (populate a list based on name of file chosen). I've tried adding an > OnChangeAjaxBehavior to my FileUploadField and implementing the > onUpdate(AjaxRequestTarget arg0) method. Unfortunately, this is not working > for me. Does anyone have any suggestions as to how I could AJAX-ify this > component? > > This is my current code: > > fileUploadField.add(new OnChangeAjaxBehavior(){ > private static final long serialVersionUID = 1L; > > @Override > protected void onUpdate(AjaxRequestTarget arg0) { > if (fileUploadField.getFileUpload() != null){ > info("Added file to list"); > final FileUpload uploadedFile = > fileUploadField.getFileUpload(); > addFile(uploadedFile); > buildListView(); > arg0.add(fileUploadField); > arg0.add(documentListItems); > arg0.add(feedback); > } > } > }); > > Thanks for your help! > > > -- > View this message in context: http://apache-wicket.1842946. > n4.nabble.com/FileUploadField-with-AJAX-Behavior-tp4677874.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
FileUploadField with AJAX Behavior
Hello everyone, I would like to perform some actions in an AJAX event after selecting a file from the file-browsing pop-up window in a FileUploadField component (populate a list based on name of file chosen). I've tried adding an OnChangeAjaxBehavior to my FileUploadField and implementing the onUpdate(AjaxRequestTarget arg0) method. Unfortunately, this is not working for me. Does anyone have any suggestions as to how I could AJAX-ify this component? This is my current code: fileUploadField.add(new OnChangeAjaxBehavior(){ private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget arg0) { if (fileUploadField.getFileUpload() != null){ info("Added file to list"); final FileUpload uploadedFile = fileUploadField.getFileUpload(); addFile(uploadedFile); buildListView(); arg0.add(fileUploadField); arg0.add(documentListItems); arg0.add(feedback); } } }); Thanks for your help! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/FileUploadField-with-AJAX-Behavior-tp4677874.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org