When converting from Java, can gwt generate .js instead of .html files? - java

I find that GWT will generate multiples HTMLS and use frame injection to invoke the JS logic in the caller HTML. But most of the browsers will not allow you to do frame injection on a local file system.
I am trying to avoid accessing different htmls on a local file system. Is there any way to generate pure JavaScript files from GWT instead of HTML ones?
Thanks!

Yes, you just have to change the linker.
Add this line in your *.gwt.xml module file to have pure .js files:
<add-linker name="xs"/>
Or this one, if you want .js files but they are executed in an iframe context.
<add-linker name="xsiframe"/>

Related

Liferay 7.1 - How to add a link html for a pdf file

I have a main module C-portlet that contains in the folder resources a pdf file.
resources/webapp/files/cg.pdf
I have a war theme. In one of its jsp page, i need to add a link for the cg.pdf.
For now, i have :
<a target="_blank" href="/o/Cportlet/src/main/resources/META-INF/resources/webapp/files/cg.pdf"><liferay-ui:message key="cg-link"/></a>
but it doesn't work.
Last point, this pdf could be changed at anytime without a deploy again a module / war.
Is anyone have an idea ?
Thanks
You can put your pdf file in one of your theme resource folders (for example the "templates" folder).
Now you can use themeDisplay.getPathThemeTemplates() + "/cg.pdf" or within your theme with freemarker "${templates_folder}/cg.pdf"
There are several ways to do this: imagining you cannot use the regular documents library... Or you module cannot use the library to get resources..
You could use a resource action if you have an MVC portlet. This would be the simplest way to just serve that resource, and you would only need to put the MVC resource command URL in you jsp. Regular portlets can also provide resources but not as easily.
For general modules you can create a struts action..which are normally way more complicated, especially if the resource is for private use only.

How to apply external HTML or CSS templating to jsp pages (NetBeans)

I'm new to Java environment and I want to know:
1) How to apply external HTML or CSS files to jsp pages(Web Application using NetBeans)
2) Is there any 'MasterPage' alternative feature in Java?
Thanks in advance.
you can either put CSS code directly in your JSP, or link to it, as usual, the real difference is where to put resources, and how to link to theme, I refer you to this page https://stackoverflow.com/a/14571407/1951298
for external HTML file, you can use JSTL : <c:import url="http://website.com/some/portion.html" />

Set path for js files generated by GWT

I have GWT application and I need to use files, generated for client side in Java EE application that doesn't use GWT. Actually, I just want to include my_app.nocache.js in some html page.
This part works fine, problems begin when my_app.nocache.js tries to load other resources, generated by GWT (other *.js files and *.css files). But I have all my resources in /_resources/mypackage/ and my_app.nocache.js doesn't know anything about this and tries to load just my_name.css instead of /_resources/mypackage/my_name.css
Is there any way to set up path for GWT to generate resource files, so it wold be same, as I use in my Java application?

Static resources in GWT apps

Do you ever need to write your own HTML, CSS or JavaScript files for your GWT app? Any reason to ever write your own HTML/CSS and include it with the build? If so, under what circumstances, and where do you package it in the final WAR?
Some developers prefer to use an external CSS file for their app instead of a CSS resource. Then you add this CSS file to your /war directory, and provide a link to it in your host page like you would do with any external CSS file.
If you use UI:Binder, which I highly recommend, you can write a lot of page or widgets' layouts in HTML as opposed to using GWT widgets. In this case you don't have to do anything with the HTML: GWT compiler will take care of it.
There is a way to use native JavaScript from inside the GWT app. Sometimes developers want a special effect or some functionality that they can't (or, quite often, don't know how to) implement in GWT. In this case you include the JavaScript code directly into your GWT code, or you use an external JavaScript file and reference it from GWT. In the latter case you include your JavaScript file in your /war directory and load it in your host page like with any JavaScript file.

Semi dynamic constants in GWT

For GWT we use static constants to provide internationalization for our users. However, this makes reviewing and editing the texts a tedious process, because if one of our stakeholders has comments, it has to be compiled and deployed to our demo environment again. The solution would be to have some kind of semi dynamic text constants.
What I would like, is that I can compile to some kind of "review mode", and when I do that, the constants are read from a file from the server or database. If possible I would like to be able to edit this file, so stakeholders can modify the texts themselves (using some kind of text edit widget I would have to write for that). Then we can develop, test and demo with these texts. If we are satisfied, we compile for production mode, which uses a old fashioned constants resource bundle, compiled completely in JavaScript.
Does somebody know if something like this exists, or have some pointers on how to implement this?
It is a very surprising situation that GWT programmers often overlook the usefulness of JSPs and the Dictionary class. Even though many of us had tons of JSP experience prior to using GWT.
Dictionary class
You can define your "static" information as javascript var objects in the html hosting file. The Dictionary class can be used to read those javascript objects any time after moduleload.
JSP
The HTML "hosting" file, i.e. the html file used for launching GWT need not be an HTML file. It can be a HTML file dynamically generated by a JSP.
If you are familiar with JSP, you could turn an HTML file into a JSP just by changing its extension. Now turn the javascript object section you used for defining GWT "static" information into being dynamically generated by the JSP.
Voila!
I use JSP as the hosting file when I need to generate user- or session- specific "static" information for the GWT client. The JSP could read from the database or from some conditionally chosen text files.

Categories