user1457390
user1457390

Reputation: 9

How to set Inputtextarea attributes to display maximum length, rows and width

I set up this html code in jsf and it doesnt limit the length of characters, it still go beyond 576 characters how do I set it up? I need to set up the rows to 4 but opted to do style to be consistent on all browsers, is this correct? Here is the code.

<td colspan="7">
 <h:outputText id="explanation1"
    value="#{handler.document.header.docDesc}"
rendered="#{documentHandler.mode != 2}"/>
 <h:inputTextarea id="explanation2" 
    value="#{documentHandler.document.header.docDesc}"
rendered="#{documentHandler.mode == 2}" 
style="height: 60px; width: 705px;"> 
    <f:validateLength maximum="576"/> 
</h:inputTextarea>   
</td>

Upvotes: 0

Views: 2483

Answers (1)

Aritz
Aritz

Reputation: 31649

First of all, as you're writing some JSF, I suggest you also migrating the HTML table and convert it into a h:dataTable. Appart from that, <f:validateLength maximum="576"/> tag is doing JSF validation, which is only done in server side. That means you're not limiting the client (browser) on typing, you perform validation only when form is sent and it's all done in server side.

To do that in client, you have to go to a Javascript/JQuery solution. Remember to assign the textArea an styleClass called max:

$('textarea.max').keyup(function() {
var $textarea = $(this);
var max = 576;
if ($textarea.val().length > max) {
    $textarea.val($textarea.val().substr(0, max));
}
});

Original link

Upvotes: 2

Related Questions