Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prevent data in h:inputTextArea from being submitted

 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using h:inputTextArea which is populated in the backing bean. The textArea is only for displaying data so I made it readOnly. The problem is that when the form is posted back, the textArea data also gets posted to the server (which I am trying to somehow avoid). The reason for avoiding posting of textArea data is that it is too large to be posted and given the default post size , "java.lang.IllegalStateException: Post too large" is thrown when the form is submitted.

How do I avoid posting of textArea data when the form is submitted?

regards,
Nirvan.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's outside the form you're submitting, it won't be posted. disabled="true" will also exclude it from submit.
 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter,
The textArea is inside the form, as I am populating it from backing bean. Making it disabled results in the content being greyed out and hence very difficult to read.

thanks and regards,
Nirvan.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello B,


the textarea doesn't need to be inside the form to populate it from the backing bean.

EDIT: little example of two ways to do it: without the JSF component and with the JSF component

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
textArea is an input control, so it's not surprising that it's input even when readonly.

Use an outputText control instead and use CSS to set its width/height to a size that suits you. And draws a textArea-style frame around the text if you want that too.
 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:


Dieter,
I never thought of using textArea that way. Thanks for that trick. I have implemented it.

regards,
Nirvan.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started to mention that one as well, but didn't think it offered anything that a pure JSF solution couldn't. I'd forgotten that TextArea scrolls, though. You can do that with a <div> as well, and by extension, a JSF panel control, but it's more work, perhaps.

For best results, however, wrap any raw HTML with the f:verbatim tag.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome! Just wanted to add one more thing:

You should know that EL-script is unsafe to use in the way I showed it, if it is unprocessed input from the user. It's no problem if you are using your own text, but if you use that textarea to output user-submitted text, know that it exposes your users to cross-site scripting.


Regards,


Dieter
 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter,
I am using the textArea to display some messages to the user. These messages come from a text file on the server . These messages have nothing to do with the user input. So I believe, that it wouldn't cause problems related to cross-site scripting (although I don't know much about that term).

regards,
Nirvan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic