user840930
user840930

Reputation: 5588

jsf h:inputText component appear based on javascript?

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

Answers (2)

BalusC
BalusC

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

Mikita Belahlazau
Mikita Belahlazau

Reputation: 15419

You can hide it on page depending on your javascript condition. Something like $('.class-of-input').hide();

Upvotes: 0

Related Questions