Wicket page is refreshed if use ajax after form is submitted with target=_blank -


i have preview button. when user press preview, form submitted on new tab show pdf file have data in form. use custom submitlink submitresourcelink

public abstract class submitresourcelink extends submitlink implements iresourcelistener { private final iresource resource;  @override public final void onresourcerequested() {     attributes = new attributes(requestcycle.get().getrequest(), requestcycle.get().getresponse(), null);     resource.respond(a); } 

implement on form

new submitresourcelink("previewbtn", form, new jasperreportsresource() {         private static final long serialversionuid = -2596569027102924489l;          @override         public byte[] getdata(attributes attributes) {             return control.getexportpreviewbytestream(estimatemodel.getobject());         }     }) {         private static final long serialversionuid = 1l;          @override         protected string gettriggerjavascript() {             string js = super.gettriggerjavascript();             js = "document.getelementbyid('" + form.getmarkupid() + "').target='_blank';" + js;             return js;         }          @override         public void onsubmit() {             form.add(attributemodifier.append("target", model.of("_blank")));             processinputs(form);             onresourcerequested();         }     }.setdefaultformprocessing(false); 

when press preview, new tab opend. when input in ajax component (ex:autocompletetextfield), ajax reponse data xml: <ajax-response><redirect>....</redirect></ajax-response> , refresh page. now, want after press preview, still use current form normaly. thank.

this caused "stale page protection" in wicket. first click opens same page instance in new tab/window. increments page's rendercount counter, i.e. says "this page has been rendered n times".
links in wicket ?2-1.ilinklistener-component~path. here '2' page id , '1' page render count. links in tab1 have rendercount 'n', , links in tab2 - 'n+1'.
clicking on link in tab1 fail stalepageexception tells wicket "the user trying use obsolete version of page. please render latest version of page user can try again".

this protection needed because user may many actions in tab3, e.g. replace panel replaces/hides link user wants click in tab1. if there no such protection wicket either fail componentnotfoundexception while trying click link or worse can wrong action if link/button in repeater , repeater has changed items in tab2.

to overcome problem should open new page instance in tab2, i.e. submits form in onsubmit() setresponsepage(getpage().getclass()). way won't re-render current page instance n+1 time.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -