1

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 2

2

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.

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

1 Comment

once the component is visible, how do I hid it again? .style = "hide"
0

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

Comments

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.