3

I have a JSF output text as shown below:

<h:outputText id="totalCount" value="#{myBean.totalCount}" />

And within my javascript- which is being called from a h:selectOneMenu, I am trying to calculate the count and set it.

var total = <some calculation is done>;
document.getElementById("myForm:totalCount").value=total;

I verified that the value was being set by adding an alert, but this was not reflecting in the page. Further noticed that outputtext was being rendered as a SPAN HTML tag.

So, will it not work in a Javascipt? Any suggestions?

Thanks for anyone who can help me.

1 Answer 1

3

This would rather be "innerHTML" than "value" in case of spans. The problem is though even if you update it on the client side, value won't be submitted to the server and will be lost on the nearest refresh. It would be safer then to add f:ajax behaviour to your menu and update value there.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the information. I had a hunch that I need to use f:ajax. I will try that out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.