Problems with newline symbol in a TextArea (works in IE but not in Firefox)

1,916 views
Skip to first unread message

LFCPD

unread,
Jan 12, 2009, 9:45:58 AM1/12/09
to Google Web Toolkit
Hi all,

In my application I insert a newline symbol in a textArea like
follows:

TextArea ta = new TextArea();
ta.setText("1.1.1.1\n1.1.1.2\n1.1.1.3");

And in IE it appears like follows inside the TextArea (and is correct
like this):
1.1.1.1
1.1.1.2
1.1.1.3

Later, in my application I have to read the content of this textArea
and recognize separately each line, and I do it by the \n symbol.

In IE it works perfectlky (it founds three elements), but not in
Firefox, it seams like Firefox doesn't know the \n symbol. I've been
looking around but I didn't find anything.

Can you help me, please?

Thanks in advance!

olivier FRESSE

unread,
Jan 12, 2009, 10:14:43 AM1/12/09
to Google-We...@googlegroups.com
If I remember well, textarea uses \r\n as newline characters, whatever the platform/browser is


2009/1/12 LFCPD <laieta.h...@gmail.com>

alex.d

unread,
Jan 13, 2009, 2:39:13 AM1/13/09
to Google Web Toolkit
Use new HTML("1.1.1.1<br>1.1.1.2<br>1.1.1.") instead.

On 12 Jan., 16:14, "olivier FRESSE" <olivier.fre...@gmail.com> wrote:
> If I remember well, textarea uses \r\n as newline characters, whatever the
> platform/browser is
>
> 2009/1/12 LFCPD <laieta.hip.hop...@gmail.com>

Lothar Kimmeringer

unread,
Jan 14, 2009, 3:19:24 AM1/14/09
to Google-We...@googlegroups.com
alex.d schrieb:

> On 12 Jan., 16:14, "olivier FRESSE" <olivier.fre...@gmail.com> wrote:
>
>> If I remember well, textarea uses \r\n as newline characters, whatever the
>> platform/browser is
>
> Use new HTML("1.1.1.1<br>1.1.1.2<br>1.1.1.") instead.

How can you enter text into a HTML-widget? I've got the same problem
like the OP and the data-source contains \r\n so the reason must be
somewhere else.


Regards, Lothar

LFCPD

unread,
Jan 19, 2009, 9:17:50 AM1/19/09
to Google Web Toolkit


Hi,

Below is attached the code I use: First of all, I fill in the text of
the textArea as follows (targetsSelected is a listBox):

String txt = "";
for (int i = 0; i < targetsSelected.getItemCount(); i++)
txt += (targetsSelected.getItemText(i) + "\r\n");

TextArea ta = new TextArea();
ta.setText(txt);
[...]

Later in the code I need to read the content of the TextArea and get
each element writen before:

int i = 0;
while (i < ta.getText().length())
{
String ip = ta.getText().substring(i, (ta.getText().indexOf("\r\n",
i)));
System.out.println("-------------------IP: " + ip);
i = ta.getText().indexOf("\r\n", i) + 1;
}

And what is printed is the following:

-------------------IP: 1.1.1.4
-------------------IP:
1.1.1.7
-------------------IP:
1.1.1.8

As you can see the second and third element have one newline at the
begining and at the end, and I can't undersand why...

Can you help me please?

Lothar, to enter text into an HTMLwidget you can use the operation
setText.
Reply all
Reply to author
Forward
0 new messages