I need to have a jsf h:inputText component appear on a web page based on whether a javascript test condition is true or not. How can I do this?
2 Answers
Just let JSF render it with CSS display property initially set to none and have JavaScript to toggle this to block.
E.g.
<h:inputText id="inputId" styleClass="hide" />
with this CSS
.hide {
display: none;
}
and this JS
if (someCondition) {
document.getElementById("formId:inputId").style.display = "block";
}
You'll only possibly run into problems with regard to input processing and conversion/validation. This input field is always submitted to the server, even when still hidden by CSS. Much better would be to evaluate that condition in JSF instead so that you can use the JSF component's rendered attribute.
1 Comment
user840930
once the component is visible, how do I hid it again? .style = "hide"