Reputation: 5588
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?
Upvotes: 1
Views: 925
Reputation: 1109735
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.
Upvotes: 2
Reputation: 15419
You can hide it on page depending on your javascript condition. Something like $('.class-of-input').hide();
Upvotes: 0