Question

I'm new to JSF and EL, and was wondering if there is a way to use EL to get the current value of an h:inputText field. Am I doing it wrong, or is it possible at all?

Thanks, -Ben

Was it helpful?

Solution

(Based on your comment) If you want to validate it server-side then you should look at an Ajax library like Richfaces.

You can then easily add an ajax call to your input field

<h:inputText id="myInput" value="#{myBean.myValue}">
   <a4j:support event="onchange" ajaxSingle="true"/>
</h:inputText>

When you change the text the Ajax call will update your model on the Server-side. If you have a validator then you can add it to the inputText tag or use the action attribute on the support tag to call another method.

OTHER TIPS

I don't really understand what you are looking for...

With this code:

<h:form id="myForm">
    <h:inputText id="myInput" value="#{myBean.myValue}"/>

The value of the input field, at the creation of the HTML page, will be equal to the value of the myValue property of the bean myBean.

If the value is changed by the user, JSF will automatically update the value of myBean.myValue when the form will be submitted.

If you need to get the value of the input on the client side, i.e. using Javascript, you need to do the following code:

<script type="text/javascript">
    function getInputTextValue() {
        var valueOfInput = document.getElementById("myForm:myInput").value;
    }
</script>

Note that you must prefix the ID by the ID of the form that contains the input ("**myForm:**myInput").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top