-2

I have a JSF page built using Prime Faces 3.3 and need to be able to enable a component when a user starts typing in text in an input text field. The text field is implemented as a h:inputText component - I tried various listeners such as

valueChangeListener="#{managedbean.onValueChange}"

but the value only gets received once the form is submitted not when the text gets changed. Is there a way to detect this ?

Thanks

3
  • public void onValueChange(ValueChangeEvent event) { UIComponent component = event.getComponent(); String clientId = component.getClientId(); if ("SelectItemComponent".equals(clientId) //Enable Another component here } if ("TextFieldComponent".equals(clientId)) { String textFieldValue = (String) event.getNewValue(); //Enable Another component here } } Dec 12, 2013 at 16:27
  • Its hard to tell what you're trygin to do. Post your xhtml and java code in your questino.
    – Makky
    Dec 12, 2013 at 16:58
  • I have a input text field on the page - how do I add a listener so that when a user enters some text the middle tier will immediately get notified and some code can get executed. Dec 12, 2013 at 17:02

1 Answer 1

1

This is how you'd do

XHTML page

<h:form id="form">  

    <h:panelGrid columns="2">  


        <p:inputText id="counter">  
            <p:ajax event="keyup" 
                    listener="#{counterBean.increment}"/>  
        </p:inputText>  


    </h:panelGrid>  

</h:form>  

BACKBEA

import java.io.Serializable;  

public class CounterBean implements Serializable{  


    public void increment() {  
        //do something 
    }  
}  

Whenever you type something it will call the increment method.

2
  • Thanks - that's a good solution to the issue and it works for me but it sends too many calls to the server - is there any event I can capture to make it simpler ? Dec 13, 2013 at 15:12
  • This was your requirement. How would you like this to be simpler?
    – Makky
    Dec 13, 2013 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.