I wrote and applet that uploads a multi-paragraph string as a param. When I test it in Netbeans, it preserves the CRLFs, but when I deploy it live, in an app, it discards them Why is this happening and what can I do about it?
Asked
Active
Viewed 129 times
2 Answers
3
Why is this happening..(?)
I don't believe the param values where ever meant to be multi-line. This is what the W3C has to say about the content of a CDATA
value..
CDATA is a sequence of characters from the document character set and may include character entities. User agents should interpret attribute values as follows:
- Replace character entities with characters,
- Ignore line feeds,
- Replace each carriage return or tab with a single space.
Suggestions
..what can I do about it?
Long 'single line' param
- Use a multi-line text component such as
JTextArea
to display and line-wrap where needed. - Use HTML formatting (including a width in CSS) into a
JLabel
. That would support multiple paragraphs. - Hard-code
\n
where needed.
Single param per line
Numbered (e.g. name=
-> text1
, text2
, ..textNNN
), stop when you get a null
value returned.

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
This is a much better answer than mine. – Anya Shenanigans Jun 16 '12 at 09:15
-
Those are all good suggestions, but they are not appropriate to what I am trying to do...paste some text into a Facebook "message" with single keystroke...or simply don't work (e.g. hard coding \n into text). Also, this does not explain why the crlf's are preserved in Netbeans but not "live" with the same code. I suspect that there is some setting I have to make, but can find no reference to it from the Google gods. – Willy Chaplin Jun 21 '12 at 10:44
-
How many questions do you intend to pack into a single 'question'? The question that was asked, has been answered. Ask another for each other question you can come up with. As far as I am concerned, this one (as quoted) is answered. In future, you might might the question more specific to the goal e.g. "How do I post an image to Facebook using Java code?" – Andrew Thompson Jun 21 '12 at 11:30
0
Yeah, this is most likely a browser thing where it replaces the CRLFs with spaces because it is in control of the parameter input. This is probably browser specific (as to the changes). The best mechanisms are to use some encoding of CRLFs and then decoding it at run-time.

Anya Shenanigans
- 91,618
- 3
- 107
- 122
-
The clipboard where the text is placed, is specific to the user's computer, not tied to any specific application. Perhaps I have not been clear about what I am trying to do. I am using a JAVA applet to transfer the text to the clipboard. It will be pasted with a single keystroke (shift-Ins) into the FB message. Everything works in Netbeans, but not "live" in which case the crlf's are discarded. – Willy Chaplin Jun 21 '12 at 10:50