Discussion:
update html field in JSP from Java (GWT)
pepgrifell
2011-04-04 10:45:17 UTC
Permalink
hi,

we are migrating our old website (based on JSP) to GWT. The
application is big and we cannot do all the changes at one, so in the
application there are some pages in GWT and some pages in JSP.

I have a JSP with some fields. One of them is a textarea. When I click
in it, a GWT window pops up with a list of values. When I click in one
of the values, I need to put the selected value in the textarea (JSP).

In GWT window, when selecting the value I call to native method (as
parameters,I pass the id of textarea field and the text to set to the
textarea.

public native void updateOldWebField(String fieldId,String newValue) /
*-{
var textfield = $doc.getElementById(fieldId);
if (textfield!=null) {
textfield.value = newValue;
}
}-*/;

But nothing is set into the textarea. Does I need to call
parent.document ? how I do that ?

Thanks,
pep
--
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-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Alexandre Ardhuin
2011-04-04 11:13:28 UTC
Permalink
Hi,

Are you sure the textarea contains the good id attribute ?
Are you sure to enter the if statement ?

You don't have to use JSNI to update the textarea. Use instead :

Element element = Document.get().getElementById(fieldId);
if (element != null) {
GWT.log("found element with id:" + fieldId);
TextAreaElement textfield = element.cast();
textfield.setValue(newValue);
}

Alexandre
Post by pepgrifell
hi,
we are migrating our old website (based on JSP) to GWT. The
application is big and we cannot do all the changes at one, so in the
application there are some pages in GWT and some pages in JSP.
I have a JSP with some fields. One of them is a textarea. When I click
in it, a GWT window pops up with a list of values. When I click in one
of the values, I need to put the selected value in the textarea (JSP).
In GWT window, when selecting the value I call to native method (as
parameters,I pass the id of textarea field and the text to set to the
textarea.
public native void updateOldWebField(String fieldId,String newValue) /
*-{
var textfield = $doc.getElementById(fieldId);
if (textfield!=null) {
textfield.value = newValue;
}
}-*/;
But nothing is set into the textarea. Does I need to call
parent.document ? how I do that ?
Thanks,
pep
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.
--
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-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
pepgrifell
2011-04-04 15:32:29 UTC
Permalink
hi,

This doesn't work for me. Myabe becasue I didn't explain how we show
the JSP. In the root panel we added a toolbar and a LayoutContainer
where, depending on the button clicked in toolbar, a different content
is shown. In some cases, inside the layoutContainer we place JSP using
a Frame. ex:

LayoutContainer mainPanel_;
mainPanel_ = new LayoutContainer();
Frame frame_ = new Frame();
frame_.getElement().setId("oldWebFrame");
frame_.setUrl(urlToShow_); //loads JSP into frame
mainPanel_.add(frame_);

After some research I have found that this code works for me:


IFrameElement iframeElement =
(IFrameElement)Document.get().getElementById("oldWebFrame");
Document document =iframeElement.getContentDocument();
Element element = document.getElementById(fieldId);
if (element != null) {
TextAreaElement textfield = element.cast();
textfield.setValue("some text to add");
}

pep.
Post by Alexandre Ardhuin
Hi,
Are you sure the textarea contains the good id attribute ?
Are you sure to enter the if statement ?
Element element = Document.get().getElementById(fieldId);
if (element != null) {
    GWT.log("found element with id:" + fieldId);
    TextAreaElement textfield = element.cast();
    textfield.setValue(newValue);
}
Alexandre
Post by pepgrifell
hi,
we are migrating our old website (based on JSP) to GWT. The
application is big and we cannot do all the changes at one, so in the
application there are some pages in GWT and some pages in JSP.
I have a JSP with some fields. One of them is a textarea. When I click
in it, a GWT window pops up with a list of values. When I click in one
of the values, I need to put the selected value in the textarea (JSP).
In GWT window, when selecting the value I call to native method (as
parameters,I pass the id of textarea field and the text to set to the
textarea.
 public native void updateOldWebField(String fieldId,String newValue) /
*-{
                   var textfield = $doc.getElementById(fieldId);
                   if (textfield!=null) {
                       textfield.value = newValue;
                   }
 }-*/;
But nothing is set into the textarea. Does I need to call
parent.document ? how I do that ?
Thanks,
pep
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.- Hide quoted text -
- Show quoted text -
--
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-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Loading...