reusing UI widgets

18 views
Skip to first unread message

sdever98

unread,
Feb 5, 2007, 6:37:44 PM2/5/07
to Google Web Toolkit
I have built a UI Widget which is very similar to the MenuBar. I want
to use this generic UI widget throughout my application and in some
cases I might have more then 1 MenuBar per JSP page. My goal is to
build one dynamic driven MenuBar that I can reuse without generating a
seperate Javascript file for each instance. The menubar I have
written loads the menubar properties, styles and items from the server
so I think I am half way there.

Is there a way to reuse this UI widget without generating new
javascript for each MenuBar? GWT will not be the container for the
Page.

If the above approach will work then I will need a method to pass
either a integer or string in the Client Entry point which will
represent which menu needs to be built. Any ideas how this would be
done?

Thanks!

Scott.

mithrandir

unread,
Feb 6, 2007, 7:42:44 AM2/6/07
to Google Web Toolkit

imho you cannot reuse the same widget instance in the same module
I encountered the same problem and ended up with swapping the widget
between two tabs by using the tab listener.

Ian Bambury

unread,
Feb 6, 2007, 9:57:55 AM2/6/07
to Google-We...@googlegroups.com
Hi mithrandir,
 
In many cases there is no problem having the same widget on different pages, certainly on different tabs. The trick is to have an abstract class as the base for each widget in the tab panel and have your common widget as a static instance in that class.

ritesh...@gmail.com

unread,
Feb 26, 2007, 5:10:22 PM2/26/07
to Google Web Toolkit
Take a look at
http://code.google.com/support/bin/answer.py?answer=55953&topic=10213

You have to use JSNI - Java Script Native Interface...

You can define a "bridge" method via JSNI that provides an external,
globally visible JavaScript function that can be called by your hand-
crafted JavaScript code. For example,

package mypackage;
public MyUtilityClass
{
public static int computeLoanInterest(int amt, float interestRate,
int term) { ... }
public static native void defineBridgeMethod() /*-{
$wnd.computeLoanInterest = function(amt, intRate, term) {
return @mypackage.MyUtilityClass::computeLoanInterest(IFI)
(amt, intRate, term);
}
}-*/;
}

On application initialization, call
MyUtilityClass.defineBridgeMethod() (e.g. from your GWT Entry Point).
This will create a function on the window object called
"computeLoanInterest" which will invoke, via JSNI, the compiled Java
method of the same name. The bridge method is needed because the GWT
compiler will obfuscate/compress/rename the names of Java methods when
it translates them to JavaScript.


Thanks

On Feb 5, 6:37 pm, "sdever98" <sde...@silverpop.com> wrote:
> I have built a UIWidgetwhich is very similar to the MenuBar. I want
> to use thisgenericUIwidgetthroughout my application and in some


> cases I might have more then 1 MenuBar per JSP page. My goal is to
> build one dynamic driven MenuBar that I can reuse without generating a
> seperate Javascript file for each instance. The menubar I have
> written loads the menubar properties, styles and items from the server
> so I think I am half way there.
>

> Is there a way to reuse this UIwidgetwithout generating new

Reply all
Reply to author
Forward
0 new messages