Retrieve a textarea from html into GWT code

154 views
Skip to first unread message

Tannu

unread,
Mar 28, 2008, 3:52:28 PM3/28/08
to Google Web Toolkit
Hi,

I am new to GWT and really need help on how to get an HTML textarea
in GWT
My html code is

<div id="text-highlight">
<textarea id="text1" class="temp javascript"
style="width:750px;height:
460px;scrolling:auto wrap:off">
</textarea>
<script src="temp/highlight.js" type="text/
javascript"></script>
</div>

I need to change text of existing text area at runtime.
I am trying with
HTML myhtml = new HTML("some string");

RootPanel.get("text1").add(myhtml); -- its giving null pointer

I tried using GWT Text area but I could not apply text highlight
javascript to that as I am using in HTML(above).

Thanks in advance...

Ian Bambury

unread,
Mar 28, 2008, 8:24:46 PM3/28/08
to Google-We...@googlegroups.com
You could try DOM.setInnerText(RootPanel.get("text1").getElement, "some string"); (something like that, anyway)
 
Ian

walden

unread,
Mar 31, 2008, 8:20:34 AM3/31/08
to Google Web Toolkit
Tannu,

Get rid of your javascript and embrace GWT. Start with the design of
your custom TextArea. Extend TextArea class and port your
'highlight.js' into Java, most likely implemented in Listeners of one
kind or another. Test that independently and get it working.

Then, to plug that into your html page, target the "text-highlight"
div with your RootPanel.get(). Once you have a handle on that
element, remove any existing content and then add an instance of your
custom TextArea (via the RootPanel API).

Walden

Peter Blazejewicz

unread,
Mar 31, 2008, 9:17:10 AM3/31/08
to Google Web Toolkit
hi,

can you post link to that javascript highlighter code? (if public
domain of course),

here is how you can use highligher used in YUI library:

HTML CODE:

<html>
<head>
<title>Wrapper HTML for SHExample</title>
<meta name='gwt:module'
content='com.mycompany.project.SHExample'/>
<link type="text/css" rel='stylesheet' href='http://
developer.yahoo.com/yui/assets/dpSyntaxHighlighter.css'/>
</head>
<body>
<script language="javascript" src="http://developer.yahoo.com/
yui/assets/dpSyntaxHighlighter.js">
</script>
<script language="javascript"
src="com.mycompany.project.SHExample.nocache.js">
</script>
</body>
</html>


JAVA CODE:

package com.mycompany.project.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class SHExample implements EntryPoint {
private Button clickMeButton;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();

final TextArea jscriptCode = new TextArea();
rootPanel.add(jscriptCode);
jscriptCode.setText("var oPushButton7 = new
YAHOO.widget.Button({ \n" +
" label:\"Add\", \n" +
" id:\"pushbutton7\", \n" +
" container:\"pushbuttonsfromjavascript
\" });");
jscriptCode.setVisibleLines(1);
jscriptCode.setCharacterWidth(60);
jscriptCode.setName("code");
jscriptCode.setStyleName("JScript");
//
highlight();

}
native void highlight()
/*-{
$wnd.dp.SyntaxHighlighter.HighlightAll('code');
}-*/;
}


to have example highligh as on that page:
http://developer.yahoo.com/yui/examples/button/btn_example01.html

regards,
Peter

Tannu

unread,
Mar 31, 2008, 10:00:25 AM3/31/08
to Google Web Toolkit
Thanks Peter,

I am using codePress for syntax highlight , www.codepress.org .

On Mar 31, 8:17 am, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:
> > <textareaid="text1" class="temp javascript"

Tannu

unread,
Mar 31, 2008, 10:14:22 AM3/31/08
to Google Web Toolkit
Thanks lan,

It didn't work...:( Do you have any idea if I use GWT TextArea and set
some javascript for it. I am using codePress to highlight syntax in
Text area.


On Mar 28, 7:24 pm, "Ian Bambury" <ianbamb...@gmail.com> wrote:
> You could try DOM.setInnerText(RootPanel.get("text1").getElement, "some
> string"); (something like that, anyway)
>
> Ianhttp://examples.roughian.com/
>

Peter Blazejewicz

unread,
Mar 31, 2008, 3:15:13 PM3/31/08
to Google Web Toolkit
hi,

I'm on OSX (mac). That library does not work at all in safari (using
3.1 here),
So cannot help much at that stage,
Basically my previous code always hides GWT text area and insert html
table above it. To "modify" text one should show GWT text area widget
back and modify text, then invoke script again,
Simliar solution should be possible with linked library I think,

regards,
Peter
Reply all
Reply to author
Forward
0 new messages