I have created a GWT module that contains a modified DatePicker
widget.

My current web page features a bunch of search criteria. When the page
is loading, it uses a Velocity Template to detect when a certain
search field needs to be a date range field. A Velocity Macro is then
called from a file containing a bunch of Velocity Macros. This will
generate two text input boxes that, when clicked, will pop up a
calendar widget for the user to select a date. The dates selected will
be turned into a date range, i.e. January 1st - February 1st. My task
is to replace these text input boxes with GWT DateBox widgets.

In my GWT module I create and publish a JSNI method:

public void onModuleLoad() {
        publish();
}

private static void createDatePicker(String divId, String inputId,
String name) {
        RootPanel.get(divId).add(new DateBox(new DatePicker(), null, new
DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy/MM/dd")),
inputId, name ));
}

private native void publish() /*-{
        $wnd.createDatePicker =
                
@com.mycompany.datepicker.client.DatePicker::createDatePicker(Ljava/
lang/String;Ljava/lang/String;Ljava/lang/String;);
}-*/;


In the Velocity Template that generates the search page, I include my
compiled GWT module's javascript file. This seems to work fine, as I
tested adding the widget to arbitrary divs in the onModuleLoad() event
and they appeared.

The Velocity template calls the macro file to generate the text inputs
wherever a date range field is located on the page. This is where I am
trying to replace the inputs with my DateBox widgets. The macro
originally just created two text input fields that ran a
showCalendar() javascript function when clicked. I have modified the
macro to look something like this:

<div id = $fieldName>

<script type="text/javascript">
createDatePicker('$fieldName', '${fieldName}_start_date',
'$fieldName');
</script>

<br />to &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />

<script type="text/javascript">
createDatePicker("$fieldName", "${fieldName}_end_date", "$fieldName");
</script>

</div>

$fieldName is a parameter passed to the Velocity Macro when it is
called.

The problem I'm having is that it cannot recognize that
createDatePicker is a method and as such I am getting an "Uncaught
ReferenceError: createDatePicker is not defined" error. When I create
a text input field inside the macro and have the onClick event fire my
method, it works and generates the DateBox widget each time the text
field is clicked.

I am very new to Javascript so it may be something simple I'm missing.
I'm starting to think GWT is just not capable of doing what I want it
to do in this situation...

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to