GWT UiBinder I18n - java

As the title says I need some help with GWT's i18n in use with UiBinder. I want to internationalize my application using static i18n. The book I use for learning only presents a way of internationalizing ui.xml files by having the compiler generate keys for Constants/Messages and a default file, but there has to be an easier way to do this. That's why I tried using the ui:with tag like this to use my internationalized constants (inside the upFace):
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace>{lang.observe}</g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
This doesn't work, the button shows the text {lang.observe} which also seems logical, but now my question is: Is there any way to use constants like this? And if not could someone explain how I should use constants in UiBinder files instead (without having the compiler generate files and keys)?

Anywhere HTML is accepted (such as within upFace), you can use <ui:msg>, <ui:text> and <ui:safehtml> (and anywhere plain text is expected, you can use <ui:msg> and <ui:text>).
So in your case:
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace><ui:text from="{lang.observe}"/></g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
See http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resources and http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources about ui:text and ui:safehtml.

You can use constants like this :
.ui.xml :
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<ui:with field="constants" type="my.client.resources.AppResources.AppConstants"/>
<g:FlowPanel>
<g:Label text="{constants.label}"/>
</g:FlowPanel>
and the AppResources interface :
public interface ApplicationResources extends ClientBundle {
public static final ApplicationConstants CONSTANTS = GWT.create(ApplicationConstants.class);
public interface ApplicationConstants extends com.google.gwt.i18n.client.Constants {
#DefaultStringValue("my label")
String label();
}
}
But for i18n you should really follow what the GWT manual says, i.e. there
is no other (clean) way than prepare all the property files (one for each language) and generate all the required permutations. This primarily delegates
to GWT all the language detection-related stuff, and the solution provided by
GWT performs quite well at runtime. The only drawback is that the compile time
is a little higher (since you'll have permutations for every browser in every language you specify).

Related

How to use CellTable.Style with GWT 2.7.0 without UiBinder?

I joined a GWT application project a few weeks ago. The codebase was started back in 2009. I am trying to replace a FlexTable with a CellTable so that I can take advantage of the sortable columns. The current version of GWT in the project is 2.7.0, but looking through the code, it looks like there are some features still used that have gone out of style. I am new to GWT, I could be wrong.
So far, things are functionally good. However, GWT seems to be overriding my attempts to update the CSS. I used the GWT dynatablerf sample as a model to add CSS to the CellTable. The TimeSlotWidget uses CellTable.Style:
interface TableResources extends CellTable.Resources {
#Override
#Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
CellTable.Style cellTableStyle();
}
And then applies it to the CellTable like this:
table = new CellTable<TimeSlotListWidget.ScheduleRow>(ROWS_IN_A_DAY,
GWT.<TableResources> create(TableResources.class));
I tried to use this approach in my code. I even omitted the CellTable.Style.DEFAULT_CSS from the value list and created my own CSS stylesheet which started as a copy of the GWT CellTable.css
I noticed that GWT TimeSlotListWidget sample has an ui.xml file with UIBinder. My project does not currently use UIBinder.
When I run my code, there is a <style> block inserted into the page that seems to be the standard GWT CellTable.css. Then directly after that, another <style> block is inserted with my CSS. And my CSS is not overriding the standard GWT CSS.
How can I keep the GWT CellTable.css from being inserted? Why is it being inserted?
The problem is that in your code, you reuse CellTable.Style, and two different ClientBundles have used the same type but each bound their own CSS to it.
Instead, extend the CellTable.Style interface, and use that in your bundle:
interface MyCellTableStyle extends CellTable.Style {}
interface TableResources extends CellTable.Resources {
#Override
#Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
MyCellTableStyle cellTableStyle();
}

Gwtbootstrap3. Using bootstrap component only with java code- without ui-binder

Is there possibile to use bootstrap3 elements (from gwtboostrap3 library) without using ui binder, but using java code like it is done with gwt regular widgets?
I could not find a word about it in Documentation.
F.E. Lets take button widget from gwt:
public void onModuleLoad() {
// Make a new button that does something when you click it.
Button b = new Button("Jump!", new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("How high?");
}
});
// Add it to the root panel.
RootPanel.get().add(b);
}
}
Which will create:
<button type="button" class="gwt-Button">Jump!</button>
In gwtbootstrap3 I have to do something like that:
<b:Button type="DEFAULT"/>
Please help me with that.
Is it possible to use gwtbootstrap3 library components like button with pure java instead of uibinder xml files?
Is there solution that works out of box?
Or maybe I should write my own classess that extends native gwt widget an add bootstrap releated css classes?
Yes!
You can use the widget as you please, refer to the their javadoc to see what constructors they have! They are a different set of widgets and might not be analogue of GWT standard widgets.
Bonus
GWT UiBinder does no different than you, all it does is reduce the boilerplate, generating java classes that automate the instantiate of the widgets. You can add the compiler option -gen to see these transient classes. Usually , they are deleted after GWT compiles your application, as they are no longer needed. Take a look the the compiler documentation for more info!

intellij not resolving el variables within JSP code inspection or autocomplete

To summarize the answer shown here Code assist in (jsp /jstl) view for Spring MVC model objects in Eclipse
is not working for me at all, is there a setting that I need to change ?
I have just downloaded the sample spring-mvc-showcase on github, and it doesn't work out of the box on that project (with either 11.1.3 or EAP 12 version both full enterprise editions), see below (I have no idea where it gets formBean from) :
Here is an example from my own project,the screen shot below (bottom frame) shows my controller adding a string attribute to model and returning correct view name. I would then expect shopString to be offered up as autocomplete option when editing that view, however it is not :
sg is a javascript variable - so great it should be there, but where is "shopString" ?.
Is there a setting I need to change or something else I am missing to get this functionality (using 11.1.3 enterprise edition with all the spring plugins).
It is also failing on spring specific variables :
IS their an open source (one of the spring tutorial projects?) where this definitely works ... or is there a setting I need change in my Intellij install (I have tested with a brand new download of the version 12 EAP) ?
One more screenshot below shows all my spring coifg files set up correctly via autodetection, but the code inspections fails ... this is the spring-mvc-showcase project :
There's a standard way to do this, which is not IntelliJ-specific.
<jsp:useBean id="someModel" scope="request" type="foo.bar.SomeModelClass"/>
The type attribute here does not need to be a concrete class, it can be an interface type as well. Typically you'd put these declarations at the start of your JSP/JSPX files, to provide something like a "declaration of model inputs".
Using JSPs in such a declarative way was recommended in the original book on Spring, in fact (Expert One-on-One J2EE Design and Development.). IntelliJ has been providing full code completion for such pages since at least 7 years.
Note that there are additional relevant convenience features in IntelliJ: if an EL variable reference is marked as undefined, you can press Alt-Enter to select a QuickFix, which will insert a declaration like above. It will even try to figure out the actual type, based on the properties you're accessing.
As I understand Spring, there is no declaration for definitions of variables that you may put into your model. The call model.addAttribute() may add an object to the model, either identified by a parameter or automatically generated by the class name of the object.
So imagine the following case where you have more than one method:
#RequestMapping("foo") public String foo(Model model) {
model.addAttribute("model", new Foo());
return new Random().nextBoolean() ? "page" : "someOtherPage";
}
#RequestMapping("bar") public String bar(Model model) {
model.addAttribute("model", new Bar());
model.addAttribute("model", new Foo());
model.addAttribute("model", new Bar());
return new Random().nextBoolean() ? "page" : "someOtherPage";
}
and the JSP would be something like
<c:out ${model.value} />
Since there is no proper mapping of which controllers may under some circumstances forward to which views, nor what exactly lies within the model, your IDE has no real chance to provide you with proper information.
But to support the IDE in suggesting you some useful information, you can use type hints. Therefore, you have to copy the whole reference of an object, e. g. foo and add a JSP comment like:
<%--#elvariable id="foo" type="com.mycompany.SomeObject"--%>
The warning will vanish and the full IDE support is on your side, allowing you to traverse the fields of foo.
One of the nicest things is that the unused getter warnings will vanish, too. You can directly call the show usages action directly from the JSP or the POJO.
This also works with JSF and particularly within JSF components. Pretty neat feature to have this kind of code completion, showing warnings and errors.
Hope that helps you with your switch to Intellij Idea.
Edit: I also reported this finding to a friend wo wrapped the whole thing into a nice blog entry. Maybe you're interested in reading it: open link
This got fixed in the latest release of intellij 122.694
I faced with similar issue when start writing my own interceptor. Problem was that I start using refference in my view resolver configuration
don't use contruction like this
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" ref="prefix"/>
<property name="suffix" ref="suffix"/>
</bean>-

How to generate locale properties file from my Messages interface?

I am implementing an internationalized GWT application at the moment. I read the related documentation and have created the necessary interface that extends com.google.gwt.i18n.client.Messages. I'd like to use MD5 key generation. The methods are annotated like this:
#DefaultMessage("Demo")
#Description("A menu item's label")
#Meaning("Nothing special so far")
String bucketDemo();
How could I automatically generate the translatable .properties files based on the interface? I see that i18nCreator is for generating the interface and the properties file the same time.
OMG, I missed the point that this file is automatically generated by the GWT Compiler.. :-)

Eclipse Code Hinting on JSP with Custom Tags (taglib)

I'm developing a JSP tag that have an attribute that works with a set of possible values.
I don't need to enforce this values, but I would like my IDE (Eclipse) do some code hinting or auto-completion.
Suppose a tag like this <mytag:sometag someattribute="value" />.
The attribute someattribute can have any value (remember, I don't need to enforce), but I would like it to suggest you the following list of values: ValueA, ValueB and ValueC
Nitin Dahyabhai at the Eclipse Community Forums suggested writing a plugin based on org.eclipse.wst.xml.core.modelQueryExtensions or create templates with the values.
The problem with templates is that I have hundreds of possible values and I have multiple tags.
The problem with writing a plugin is that I haven't time or knowledge to do it.
Is there another way to do it?
In case you end up with writing Eclipse extension for modelQueryExtensions, that should be as simple as:
Create new plug-in: com.my.taglib, and add to its plugin.xml:
<extension point="org.eclipse.wst.xml.core.modelQueryExtensions">
<modelQueryExtension
class="com.my.taglib.MyTaglibModelQueryExtension"
contentType="org.eclipse.wst.html.core.htmlsource">
</modelQueryExtension>
</extension>
Then implement com.my.taglib.MyTaglibModelQueryExtension class:
public class MyTaglibModelQueryExtension extends ModelQueryExtension {
public String[] getAttributeValues(Element e, String namespace, String name) {
// See XSDModelQueryExtension for an example implementation of this...
}
}

Categories

Resources