Showing posts with label GWT. Show all posts
Showing posts with label GWT. Show all posts

Tuesday, June 10, 2008

How to get the tag name of a DOM element with GWT?

Surprisingly it is not possible to get the tag name value of a DOM element through the GWT API. For instance for a DOM element of a form, I would like to get the "FORM" string as a result.

Obviously it is possible to come with its own solution using the JSNI (java script native integration) and return the nodeName attribute of a DOM element, here is what I wrote:


public class Utils
{
/**
* Returns an element tag name.
*
* @param element the element to obtain the tag name from
* @return the tag name value
*/
public static native String getTagName(Element element)
/*-{
// It should work with all browsers, if it does not, replace that with more appropriate code :-)
return element.nodeName;
}-*/;
}



There is probably a good reason explaining why it is not possible to get such a value, but for now it is unknown to me.

Sunday, May 4, 2008

GWT hosted mode on Leopard tip

If you are experiencing issues when running GWT in hosted mode on Leopard it is normal.

There are a few issues in the official release of GWT and Java implementation on Leopard that prevent to execute the hosted mode runtime on Leopard (but the rest is fine). Basically the hosted mode runtime pops up and just quit a couple of seconds after.

So you need to download a patched version of GWT for Leopard, you can read more about it on this thread on GWT forums which is *the* thread to follow.

Saturday, May 3, 2008

GWT in-place-editor

The in place editor is one of the simplest yet powerful feature brought by Ajax.
I wrote two such editors last year, one using javascript and one leveraging Prototype as an exercise. Recently I started to study GWT more in depth and I found fun to write a GWT version of the in place editor.
I used the TextBox and Label widgets that will be used to display and edit the label.
The DeckPanel panel is used to alternate the display between the text box and the label widgets.
The interaction is performed using listeners. The ClickListener on the label copies the label value to the text box and switch the deck panel to show the text box. The KeyboadListener allows on the enter keystroke to copy the edited value to the label and switch back the deck panel to show the label.

public void onModuleLoad()
{
final DeckPanel deck = new DeckPanel();
final Label label = new Label("Initial Value");
final TextBox text = new TextBox();

// Wire the widgets
deck.add(label);
deck.add(text);
deck.showWidget(0);

//
label.addClickListener(new ClickListener()
{
public void onClick(Widget widget)
{
String value = label.getText();
text.setText(value);
deck.showWidget(1);
text.setFocus(true);
}
});

//
text.addKeyboardListener(new KeyboardListenerAdapter()
{
public void onKeyPress(Widget widget, char c, int i)
{
if (c == KEY_ENTER)
{
String value = text.getText();
label.setText(value);
deck.showWidget(0);
}
else if (c == KEY_ESCAPE)
{
deck.showWidget(0);
}
}
});

//
VerticalPanel vp = new VerticalPanel();
vp.add(deck);
RootPanel.get().add(vp);
}


The demo is available here.

Friday, July 13, 2007

GWT Portlet

I am glad to read Xantorohara's blog with a post that covers the integration of a GWT application as a Portlet using JBoss Portal as runtime platform :-) (although the example can be deployed everywhere).

His blog looks very promising as the example is very complete and gives all the details and files to reproduce it. I am eagger to read his next posts!!!