GWT Formpanel POST issue - servlets

I am using GWT FormPanel to submit a POST request to a servlet which renders a pdf. The screen I am using to post have got a pop up with yes, no and preview button. yes and preview would open a pdf in new tab in browser.
The problem is when I use IE11 and clicks on preview it opens up a pdf well, I dont close the tab go back to previous screen and clicks yes, again request reaches to servlet but this time all the request parameters are null.
If the pdf tab is closed and then I click on yes it again works fine. This is an issue with IE11, works fine with Chrome. Any Ideas ?
If I change it to GET it works fine but I have a huge data that needs to be passed to servlet.
here is a code snippet :
formPanel.setBodyBorder(false);
formPanel.setBorders(false);
formPanel.setHeaderVisible(true);
formPanel.setAction(someURL+ "/someServlet");
formPanel.setMethod(Method.POST);
formPanel.setTarget("somePDF");
formPanel.setId("report");
HiddenField<String> hddnF = new HiddenField<String>();
hddnF.setName("Yogi");
hddnF.setValue("Value is set...");
formPanel.add(hddnF);
formPanel.submit();
Have overridden setTarget to show result(pdf) into new popup/tab
public native void setTarget(String target)/*-{
this.#com.extjs.gxt.ui.client.widget.form.FormPanel::setTarget(Ljava/lang/String;)(target);
}-*/;

Related

Forcing to Close Chrome Custom Tab

I want to close a chrome Custom Tab with clicking device back button, but it only works when the custom tab has no history for the moment; when there's a remaining history, clicking the device back button only rewinds the custom tab back to a page in its history. Can I force the custom tab to ignore the history at any point and close the custom tab immediately?
I tried different options for the custom tabs such as below, but it appears none helps with my purpose. I would hugely appreciate your idea. Thank you!
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
My current code is
String url = eacharticle.get("url");
String PACKAGE_NAME = "com.android.chrome";
android.support.customtabs.CustomTabsIntent customTabsIntent = new android.support.customtabs.CustomTabsIntent.Builder().setShowTitle(true).build();
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
customTabsIntent.intent.setData(Uri.parse(url));
java.util.List<android.content.pm.ResolveInfo> resolveInfoList = context.getPackageManager().queryIntentActivities(customTabsIntent.intent, android.content.pm.PackageManager.MATCH_DEFAULT_ONLY);
for (android.content.pm.ResolveInfo resolveInfo : resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if(PACKAGE_NAME.equals(packageName))
customTabsIntent.intent.setPackage(PACKAGE_NAME); // force use chrome if installed
}
customTabsIntent.launchUrl(context, Uri.parse(url));
I dont think there is currently an option to do this since we cannot override onBackPressed action on chrome custom tabs. Actually it is better to work this way in many use case.

Symfony4 - isXmlHttpRequest showing wrong data

I'm not sure how to explain my problem.
I have a controller that has this piece of code to check if URL is accessed using ajax or not.
//check if ajax request
if ($request->isXmlHttpRequest()) {
...
} else {
...
}
If url is accessed using ajax it's returning JSON if not it's returning view.
When I access this URL in chrome it's showing right data(view) but if I move to for example google.com and click "back arrow" in Chrome's UI, it takes me back to my URL but now it's showing JSON.
Everything is working fine in Safari, so I'm not sure where is the problem and what to do...
Any ideas?
UPDATE: Same code works fine on Symfony 3.3
Fix: #Cache(vary={"X-Requested-With"})

Print Friendly Page

So I would like to be able to have a print button for entries in our database so users can print an entry via a print friendly "form".
My thought was to create a separate page, add labels and have those labels pull the relevant information.
I know I can add the open widget information via this code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showPage(app.pages.TestPrint);
But I'm running into a few problems:
I can't get the page to open in a new window. Is this possible?
window.open(app.pages.TestPrint);
Just gives me a blank page. Does the browser lose the widget source once the new window opens?
I can't get the print option (either onClick or onDataLoad) to print JUST the image (or widget). I run
window.print();
And it includes headers + scroll bars. Do I need to be running a client side script instead?
Any help would be appreciated. Thank you!
To get exactly what you'd want you'd have to do a lot of work.
Here is my suggested, simpler answer:
Don't open up a new tab. If you use showPage like you mention, and provide a "back" button on the page to go back to where you were, you'll get pretty much everything you need. If you don't want the back to show up when you print, then you can setVisibility(false) on the button before you print, then print, then setVisibility(true).
I'll give a quick summary of how you could do this with a new tab, but it's pretty involved so I can't go into details without trying it myself. The basic idea, is you want to open the page with a full URL, just like a user was navigating to it.
You can use #TestPrint to indicate which page you want to load. You also need the URL of your application, which as far as I can remember is only available in a server-side script using the Apps Script method: ScriptApp.getService().getUrl(). On top of this, you'll probably need to pass in the key so that your page knows what data to load.
So given this, you need to assemble a url by calling a server script, then appending the key property to it. In the end you want a url something like:
https://www.script.google.com/yourappaddress#TestPage?key=keyOfYourModel.
Then on TestPage you need to read the key, and load data for that key. (You can read the key using google.script.url).
Alternatively, I think there are some tricks you can play by opening a blank window and then writing directly to its DOM, but I've never tried that, and since Apps Script runs inside an iframe I'm not sure if it's possible. If I get a chance I'll play with it and update this answer, but for your own reference you could look here: create html page and print to new tab in javascript
I'm imagining something like that, except that your page an write it's html content. Something like:
var winPrint = window.open('', '_blank', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write(app.pages.TestPage.getElement().innerHTML);
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close();
Hope one of those three options helps :)
So here is what I ended up doing. It isn't elegant, but it works.
I added a Print Button to a Page Fragment that pops up when a user edits a database entry.
Database Edit Button code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showDialog(app.pageFragments.FragmentName);
That Print Button goes to a different (full) Page and closes the Fragment.
Print Button Code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showPage(app.pages.ModelName_Print);
app.closeDialog();
I made sure to make the new Print Page was small enough so that Chrome fits it properly into a 8.5 x 11" page (728x975).
I then created a Panel that fills the page and populated the page with Labels
#datasource.item.FieldName
I then put the following into the onDataLoad for the Panel
window.print();
So now when the user presses the Print Button in the Fragment they are taken to this new page and after the data loads they automatically get a print dialog.
The only downside is that after printing the user has to use a back button I added to return to the database page.
1.
As far as I know, you cannot combine window.open with app.pages.*, because
window.open would require url parameter at least, while app.pages.* is essentially an internal routing mechanism provided by App Maker, and it returns page object back, suitable for for switching between pages, or opening dialogs.
2.
You would probably need to style your page first, so like it includes things you would like to have printed out. To do so please use #media print
ex: We have a button on the page and would like to hide it from print page
#media print {
.app-NewPage-Button1 {
display : none;
}
}
Hope it helps.
1. Here is how it is done, in a pop up window, without messing up the current page (client script):
function print(widget, title){
var content=widget.getElement().innerHTML;
var win = window.open('', 'printWindow', 'height=600,width=800');
win.document.write('<head><title>'+title+'/title></head>');
win.document.write('<body>'+content+'</body>');
win.document.close();
win.focus();
win.print();
win.close();
}
and the onclick handler for the button is:
print(widget.root.descendants.PageFragment1, 'test');
In this example, PageFragment1 is a page fragment on the current page, hidden by adding a style with namehidden with definition .hidden{display:none;} (this is different than visible which in App Maker seems to remove the item from the DOM). Works perfectly...
2. You cannot open pages from the app in another tab. In principle something like this would do it:
var w=window.parent.parent;
w.open(w.location.protocol+'//'+w.location.host+w.location.pathname+'#PrintPage', '_blank');
But since the app is running in frame nested two deep from the launching page, and with a different origin, you will not be able to access the url that you need (the above code results in a cross origin frame access error). So you would have to hard code the URL, which changes at deployment, so it gets ugly very fast. Not that you want to anyway, the load time of an app should discourage you from wanting to do that anyway.

download from popup in Casperjs

I'm scraping a weird ASP-based site. I want to download an XML file. To get the download normally, I fill out a form, click "download", then a popup comes up and the file downloads automatically (in both chrome and firefox).
What seems to ultimately trigger the download is a GET request to an 'www.HOST.content/xmlfile.aspx' url which gets a 'content-disposition:attachment' with a filename 'xmldocumentIcareabout.xml'
While I can see this request/response using the developer console in chrome (on the popup page), I do not see these events in 'resource.requested' or 'resource.received' on the Casperjs side.
What I've tried so far:
Explicit call to 'this.download('www.HOST.content/xmlfile.aspx')
Post call using the form: 'this.download('www.HOST.content/form.aspx',downloadPath,'POST', postBody)' where 'postBody' has all the form information and the __EVENT_TARGET
Trying to replicate the GET request with this.open('www.HOST.content/xmlfile.aspx')
What other approaches can be used so that I can catch an automatic download event from a popup window in Casperjs?
Fixed by calling 'download()' within the popUp frame (in the 'then()' function of 'withPopup()'

Selenium and iframe

I have an iframe that gets loaded when i click on a tab on a page. When i use Firebug to look at the iframe on IE8, all i see is:
iframe id=tabContextFrame class=contextFrame contentEditable=inherit src=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 name=tabContextFrame url=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 scrolling=auto
and that's it.The hierarchy below the iframe can't be seen. I want to click on a link within the iframe. To find the elements within the iframe, I did a selenium.click("on the tab that loads the iframe") and then selenium.getHtmlSource(). From this source, I can at least locate my link of interest. I did a selenium.click("//span[text()='Link']") but it doesn't seem to do anything. Any ideas please?
Here is the code:
selenium.click("//span[text()='tab that loads iframe']");
Thread.sleep(5000);
selenium.selectFrame("tabContextFrame");
selenium.mouseOver("//span[text()='Link']");
selenium.mouseDown("//span[text()='Link']");
selenium.mouseUp("//span[text()='Link']");
Thread.sleep(5000);
selenium.selectFrame("null");
I'm guessing you are using Selenium 1.0. Have you looked at Selenium 2.0 and WebDriver. I found the following and it worked for me:
Q: How do I type into a contentEditable iframe? A: Assuming that the
iframe is named "foo":
driver.switchTo().frame("foo");
WebElement editable = driver.switchTo().activeElement();
editable.sendKeys("Your text here");
Sometimes this doesn't work, and this is because the iframe
doesn't have any content. On Firefox you can execute the following
before "sendKeys":
((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'");
This is needed because the iframe has no content by default:
there's nothing to send keyboard input to. This method call inserts an
empty tag, which sets everything up nicely.
Remember to switch out of the frame once you're done (as all further
interactions will be with this specific frame):
driver.switchTo().defaultContent();
I found this on http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
Use driver.switchTo().defaultContent(); first then do your operation

Resources