Open a new instance of GWT app - java

I'm developing a GWT web App . Righ now I have one default EntryPoint: AppWeb.
The page works perfectly if I run it in the web browser:
http://localhost/AppWeb.
If I open a new tab, and write the same URL, the App works just fine as two instances.
Now, I just want that a simple button in my app open a new windows of the same app and same entry point, just like a new instance. But is not working. I'm using this:
Window.open("AppWeb?guiId=xxx", "_blank", "");
The problem is that the new tab is openen, but is not calling the onModuleLoad of the AppWeb entry point.

I think you could do it using an anchor http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/Anchor.html
Set the anchor target with
myAnchor.setTarget("_blank");
in your code and in the ui
<g:Anchor ui:field='my anchor' href='' text='click here to duplicate'/>
Note the empty href='' (because it would be appended to your current url).
I tried it and it calls onModuleLoad() when the entry point is called on the new tab.

Related

I can't create an external link (href) that open itself without the localhost:8080 in front of it

I'm trying to create a link (href) that open itself in a new page. Should be "simple".
That's the focus code:
if (propertybox.getValue(CandidatoLink.LINK) != null) {
Anchor anchor = new Anchor(propertybox.getValue(CandidatoLink.LINK),
propertybox.getValue(CandidatoLink.LINK));
anchor.setTarget("_blank");
return anchor;
}
This is to get the link from the database, like "www.google.com":
propertybox.getValue(CandidatoLink.LINK));
This is to get the link opening in a new tab of the browser:
anchor.setTarget("_blank");
It works all just fine: I can get the link opened in a new tab. The only problem is that the system think that's an intern page of the website and sees it as a Route! That's the problem. It will open a new tab with this link: http://localhost:8080/www.google.com
I can't remove the first part (http://localhost:8080/). Can someone help me?
I use Java 11.0.15, Vaadin 14 (Maven/Spring Boot) and my IDE is Eclipse 2022-06 (4.24.0).

Cannot go to "chrome://downloads/" in a newly opened tab with Selenium in Chrome

I am using Selenium and Java to write a test for Chrome browser. My problem is that somewhere in my test, I download something and it covers a web element. I need to close that download bar (I cannot scroll to the element). I searched a lot and narrowed down to this way to open the download page in a new tab:
((JavascriptExecutor) driver).executeScript("window.open('chrome://downloads/');");
It opens that new tab, but does not go to download page.
I also added this one:
driver.switchTo().window(tabs2.get(1));
driver.get("chrome://downloads/");
but it didn't work either.
I tried:
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");
and
action.sendKeys(Keys.CONTROL+ "j").build().perform();
action.keyUp(Keys.CONTROL).build().perform();
Thread.sleep(500);
but neither one even opened the tab.
It is because you can't open local resources programmatically.
Chrome raises an error:
Not allowed to load local resource: chrome://downloads/
Working solution is to run Chrome with following flags:
--disable-web-security --user-data-dir="C:\chrome_insecure"
But this trick doesn't work with Selenium Chrome Driver(I don't know actually why, a tried to remove all args that appears in chrome://version, but this doesn't helps).
So for me above solution is the only one that works:
C# example:
driver.Navigate().GoToUrl("chrome://downloads/")
There is another trick if you need to open downloaded file:
JavaScript example:
document.getElementsByTagName("downloads-manager")[0].shadowRoot.children["downloads-list"]._physicalItems[0].content.querySelectorAll("#file-link")[0].click()
Chrome uses Polymer and Shadow DOM so there is no easy way to query #file-link item.
Also you need to execute .click() method with JavaScript programatically because there is a custom event handler on it, which opens actual downloaded file instead of href attribute which point to url where you downloaded file from.
I started with this post and ended up with the solution given below. This one works in Chrome 71. First I highlighted the control and then clicked it.
The window object is actually the IWebDriver, the second method is called after the first one.
internal void NavigateToDownloads()
{
window.Navigate().GoToUrl("chrome://downloads/");
}
internal void OpenFirstDownloadLinkJS()
{
IJavaScriptExecutor js = (IJavaScriptExecutor) window;
js.ExecuteScript("document.getElementsByTagName('downloads-manager')[0].shadowRoot.children[4].children[0].children[1].shadowRoot.querySelectorAll('#content')[0].querySelector('#details > #title-area > #file-link').setAttribute('style', 'background: yellow;border: 2px solid red;');");
js.ExecuteScript("document.getElementsByTagName('downloads-manager')[0].shadowRoot.children[4].children[0].children[1].shadowRoot.querySelectorAll('#content')[0].querySelector('#details > #title-area > #file-link').click();");
}
Use this code (I wrote it in Python, but it should work in Java too with very slight modifications):
#switching to new window
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
#opening downloads
driver.get('chrome://downloads/')
#closing downloads:
driver.close()

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Open anew window using java

Is there any way to open a new window with a specified URL using java only.I know that we can use window.open in javascript but i need it to be in java page.Anyidea?.
You can use Applet's context and the showDocument() method.
Example:
String link = "http://www.google.com";
URL u = new URL(link);
AppletContext a = getAppletContext();
a.showDocument(u,"_self");
You can change the window/tab opening the link by changing the _self to _blank
If it's indeed an applet, and you want to create a Java window (JFrame or similar), see AlphaMale's comment.
If what you want instead is a new browser window, you can either follow inquizitive's answer, or alternatively use JSObject to run arbitrary JavaScript code:
import netscape.javascript.*; // add plugin.jar to classpath during compilation
...
JSObject window = JSObject.getWindow(this);
window.eval('window.open(url)');
This is more useful to interact with the page's scripts, of course, if what you want is just open another tab using the Applet API may be simpler.

Implementing MixedParamUrlCodingStrategy prevents my site from using CSS

I developed an application in Wicket with a CSS-styled left menu. Everything worked fine. Then, to get the URLs to be RESTful, I changed WicketApplication.java to use MixedParamUrlCodingStrategy. From then on, the style stopped working. I don't know where the problem is. I didn't change anything else. Here's my code:
mount("/site",PackageName.forPackage(WelcomePage.class.getPackage()));
//
mount("/download",PackageName.forPackage(AppDownloadApi.class.getPackage()));
// mountBookmarkablePage("push/reg", PushRegApi.class);
mountBookmarkablePage("push/send", PushMessageApi.class);
mountBookmarkablePage("device", DeviceprofileExportAsXML.class);
// mountBookmarkablePage("app/download", AppDownloadApi.class);
// mountBookmarkablePage("ds/export", ExportDataSource.class);
// mountBookmarkablePage("control/export", ExportAsXML.class);
MixedParamUrlCodingStrategy ds = new MixedParamUrlCodingStrategy(
"ds", ExportDataSource.class, new String[]{"name"});
mount(ds);
MixedParamUrlCodingStrategy control = new MixedParamUrlCodingStrategy(
"control", ExportAsXML.class, new String[]{"controlName"});
mount(control);
MixedParamUrlCodingStrategy app = new MixedParamUrlCodingStrategy(
"app", AppDownloadApi.class, new String[]{"appId"});
mount(app);
MixedParamUrlCodingStrategy pushReg = new MixedParamUrlCodingStrategy(
enter code here "push/reg", PushRegApi.class, new String[]{"appName",
"groupName","userName","password","deviceToken"});
mount(pushReg);
If I uncomment the comments, and remove MixedParamUrlCodingStrategy, then everything works fine. How can I have both RESTful URLs and my desired style?
This could be an issue with how you are linking your CSS into the pages. We had a simmilar issue when first starting as we had hardcoded the path to CSS into the page, but then when we changed the mappings of some pages the relative paths to the CSS files were nolonger valid.
I would suggest to use FireBug and check the Net tab to see if the CSS is loading, and if so what the contents of the request returns.
You may need to use something like the CSSPackageResource.getHeaderContributer to link the css to the page correctly.

Categories

Resources