Search code examples
javajsficefacesicefaces-1.8

icefaces spinner listener?


I am using an enterprise component from icefaces: numberSpinner

I know how to initialize it from the bean, for instance:

processorAlSpinner =  new NumberSpinner(1,1,100,null)

where the constructor is defined in their source code like:

public NumberSpinner(int number, java.lang.Integer min, java.lang.Integer max, com.icesoft.faces.facelets.component.spinner.INumberSpinnerListener spinnerListener);

What I do not know is how to specify a listener for it? (you noticed that I put null)

Their source code says:

Specify an instance of INumberSpinnerListener in the constructor if you would like to receive value change events

but how? I tried it like:

public INumberSpinnerListener testSpinnerListener() {
    logger.info("Listener called!!!!!!!!!!!!!");
    return null;
}

processorAlSpinner =  new NumberSpinner(1,1,100,testSpinnerListener)

but the listener is not called when I change the spinner's value from UI so I think I am wrong...

Can you please give a helping hand?


Solution

  • INumberSpinnerListener is an interface (I am assuming by the name), you thus need to create a class that implements that interface, e.g.:

    class MyListener implements INumberSpinnerListener {
        // ... implementations of all the methods in the listener
    }
    

    Then you provide an instance of it in the call, e.g.:

    processorAlSpinner =  new NumberSpinner(1,1,100, new MyListener());
    

    If the interface is simple, you can also define an anonymous class directly, something like:

    processorAlSpinner =  new NumberSpinner(1,1,100, new INumberSpinnerListener() {
        // ... implementations of all the methods in the listener
    });