-
1. Re: How would I start to do a character count on a textarea?
sivaprasad9394 Aug 31, 2010 10:03 PM (in response to samuraicoder)1 of 1 people found this helpful<h:inputTextarea id="shortDescription" cols="80" rows="3"
value="#{itemHome.instance.longDescription}"><a:support event="onkeyup" reRender="echo, count"/>
</h:inputTextarea>
<h:outputLabel value="" for="" />
In <a4j:support you have actionListener adnd call the backing bean and set the value for the h:outputLabel, specifiy the id for the h:outputLabel and reRender it in <a4j:support
try like this ,
reRender="p_descriptionField,eDescriptionField"
<a4j:outputPanel id="p_descriptionField"><h:outputLabel id="eDescriptionField" value="beanname.property" for="shortDescription" /></a4j:outputPanel> -
2. Re: How would I start to do a character count on a textarea?
ahoehma Sep 1, 2010 2:28 AM (in response to sivaprasad9394)Keep it simple<h:inputTextarea id="shortDescription" cols="80" rows="3"value="#{itemHome.instance.longDescription}"><a:support event="onkeyup" reRender="count" limitToList="true"/></h:inputTextarea><h:outputLabel id="count" value="#{fn:length(itemHome.instance.longDescription)}"/>For the fn:length function see https://facelets.dev.java.net/nonav/docs/dev/docbook.html#taglib-available-jstl
If you don't like the fn:length function you can put a other getter into your beanint getTextAreaLength() ... there you must calculate the length of the #{itemHome.instance.longDescription} value<h:outputLabel id="count" value="#{bean.textAreaLength}"/>
Use limitToList=true to submit only this single text-area.At at least you can calculate the length of the text-area on client side via javascript.regardsandreas -
3. Re: How would I start to do a character count on a textarea?
samuraicoder Sep 1, 2010 10:11 AM (in response to ahoehma)HTTP Status 503 - Concurrent call to conversation
type Status report
message Concurrent call to conversation
description The requested service (Concurrent call to conversation) is not currently available.
I tried the fn:length approach with a4j:support....
You see the results... something about SEAM and the conversation scope I am guessing.
I will have to try a backing bean or javascript.
I really liked this first approach the best cause it was simplest!
UPDATE: I was able to use the a4j:support attribute ignoreDupResponses = "true" and it solved the error problem.
-
4. Re: How would I start to do a character count on a textarea?
ilya_shaikovsky Sep 1, 2010 9:59 AM (in response to samuraicoder)1 of 1 people found this helpfulI highly recommed to use some JS solution.. My concern is that having bunch of requests fired by keyup just to cound character in input(if you not need to update them at backend so often) - typical "too much ajax" case
-
5. Re: How would I start to do a character count on a textarea?
samuraicoder Sep 1, 2010 10:17 AM (in response to ilya_shaikovsky)Ilya Shaikovsky wrote:
I highly recommed to use some JS solution.. My concern is that having bunch of requests fired by keyup just to cound character in input(if you not need to update them at backend so often) - typical "too much ajax" case
Thank you for your reply.
I first tried a javascript approach. But because my Id's look like this:
<textarea rows="3" id="item:shortDescriptionDecoration:shortDescription">
I can't get the javascript to regonize it as a valid field name.
onkeydown="textCounter(document.item.item:shortDescriptionDecoration:shortDescription,document.item.item:shortDescriptionDecoration:remLen2,200)"
onkeyup="textCounter(document.item.item:shortDescriptionDecoration:shortDescription,document.item.item:shortDescriptionDecoration:remLen2,200)"function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}Any recommendations on how to get an ID that can be recognized as valid?
-
6. Re: How would I start to do a character count on a textarea?
ilya_shaikovsky Sep 1, 2010 10:42 AM (in response to samuraicoder)you passing elements to function?
then use:
onkeydown="textCounter(#{rich:element('shortDescription')},#{rich:element('remLen2'),200)"
-
7. Re: How would I start to do a character count on a textarea?
samuraicoder Sep 1, 2010 12:57 PM (in response to ilya_shaikovsky)Ahhh your the best! Thank you, I did not know about the rich:element.
Javascript counts the characters faster than the ajax can as well so I will stick with the JavaScript solution.