Change the value of <p: commandButton> using JavaScript
1 answer
JSF generates HTML. JavaScript works with HTML. When writing JavaScript code, do not look too much at the JSF source code, if you can no longer determine the shape of the top of the head, which HTML code will generate.
Open the JSF page in your favorite browser, right-click and select View Source. The generated HTML output <p:commandButton value="foo" />
as follows:
<button id="formId:buttonId" name="formId:buttonId" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="PrimeFaces.ab({formId:'formId',source:'formId:buttonId',process:'@all'});return false;" type="submit"> <span class="ui-button-text">foo</span> </button>
Look, the button has one child <span>
with this value.
So, this piece of JS, to change the value of the button to bar
, should do:
document.getElementById("formId:buttonId").firstChild.innerHTML = "bar";
+5