montu gupta
montu gupta

Reputation: 1

How to add listener to optionsGroup in Java Vaadin?

How can i add event listener to OptionGroup in java vaadin.

            OptionGroup group = new OptionGroup("Star Rating");
            group.addItem("1 star");
            group.addItem("2 star");
            group.addItem("3 star");
            group.addItem("4 star");
            group.addItem("5 star");
            group.addStyleName("horizontal");
            group.setSizeUndefined();

In the above example i want to add listener to on selecting value in radion button so that i can store value in mysql for star rating. How can i implement that?

Upvotes: 0

Views: 217

Answers (1)

André Schild
André Schild

Reputation: 4754

On most input components you can add a ValueChangeListener.

According to the javadoc the OptionGroup has this as well.

So your code looks like this:

group.setImmediate(true);
group.addValueChangeListener(new ValueChangeListener() 
   {
       @Override
       public void valueChange(Property.ValueChangeEvent event) 
       {
            // Handle value change
       }
 });

The setImmediate(true); is important, otherwise the event is delayed until the focus is lost or another interaction happens.

Upvotes: 2

Related Questions