FlexibleOptionGroup

Hi,

you cannot call the constructor of the FlexibleOptionGroupItemComponent class. This example from add-on’s Directory page shows how to use it:

// Don't add FlexibleOptionGroup to application
FlexibleOptionGroup fop = new FlexibleOptionGroup();
fop.setContainerDataSource(createTestContainer());
fop.setItemCaptionPropertyId(CAPTION_PROPERTY);
fop.setItemIconPropertyId(ICON_PROPERTY);

HorizontalLayout optionGroupLayout = new HorizontalLayout();
for (Iterator<FlexibleOptionGroupItemComponent> iter = fop
                .getItemComponentIterator(); iter.hasNext();) {
        FlexibleOptionGroupItemComponent comp = iter.next();

        // Add FlexibleOptionGroupItemComponents instead
        optionGroupLayout.addComponent(comp);

        Label captionLabel = new Label();
        captionLabel.setIcon(comp.getIcon());
        captionLabel.setCaption(comp.getCaption());
        optionGroupLayout.addComponent(captionLabel);
}
mainWindow.addComponent(optionGroupLayout); 

-Henri

Hi Henri,

The FlexibleOptionGroup component is very useful. I just have a few questions regarding this:

  1. How to handle the radio button or checkbox click event?
  2. How to check if the radio or checkbox is in selected or in de-selected state?
  3. How to programatically clear or reset the selection of radio buttons?

Your response would be very helpful.

Thanks,
Rohan

Hi Rohan,

Hope my answers are useful to u…
2. You can check if radio/ checkbox is selected/ de-selected using

flexibleoptiongroup.isSelected(Object itemid).

  1. To set/unset, flexibleoptiongroup.select(itemid) / flexibleoptiongroup.unselect(itemid).

Thanks,
Poovannan

how to solve this problem?

How to handle the radio button or checkbox click event?

you didn’t answer rohan’s first question, and i have the same problem, any ClickListen event or

tell me how to implement this funtion, thanks~

Thanks for the reply Poovannan. However, I am still waiting for the answer to my 1st question. For time being, I managed to use Layout listener which holds FelxiOptionGroupComponent and associated Label. But this just seems like a workaround to me.

Dear Henri

I am tryingg to use the addon, with 7.2.2 with MVP and CDI implementation, but i get this error

Widgetset ‘com.vaadin.DefaultWidgetSet’ does not contain implementation for org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroupItemComponent. Check its component connector’s @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.

private void setRolesContainer(BeanItemContainer rolesContainer, User u, boolean isReadOnly) {
flexOptionsRoles = new FlexibleOptionGroup(rolesContainer);
flexOptionsRoles.setItemCaptionPropertyId(“name”);
// flexOptionsRoles.setContainerDataSource(rolesContainer);
flexOptionsRoles.setImmediate(true);
flexOptionsRoles.setMultiSelect(true);
flexOptionsRoles.setReadOnly(isReadOnly);

    for (Iterator<FlexibleOptionGroupItemComponent> iter = flexOptionsRoles.getItemComponentIterator(); iter.hasNext();) {

        FlexibleOptionGroupItemComponent compItem = iter.next();

        if (u.getRoles() != null) {
            for (Role role : u.getRoles()) {

                String strRoleName = compItem.getCaption();
                String strSelected = role.getName();

                if (strSelected.equalsIgnoreCase(strRoleName)) {
                    System.out.println(".......EmployeeForm.setRolesContainer() role selected: " + strRoleName + "  ItemComponent " + strSelected);
                    flexOptionsRoles.select(compItem);
                }
            }
        }

        rolesLayout.addComponent(compItem);
        Label captionLabel = new Label();
        captionLabel.setCaption(compItem.getCaption());
        rolesLayout.addComponent(captionLabel);
    }

}

I’m also having this issue. Would be nice if somebody had a solution.
It would be even nicer if Vaadin supported laying out radio buttons any way we need to.

Hi,

there above error message means that you need to compile your own widgetset what would contain client-side part of the FlexibleOptionGroup addon. You can do this for example by using Vaadin Eclipse plugin or Maven. Take a look at the
Book of Vaadin
.

-Henri

Version 2.2.0 of the addon has been released. It’s again compiled with Java 6!

Does this support adding tooltips for items? Unlike native OptionGroup.

Hi,

Yes, it supports because you can use any component (for example a Label) as Item.

Thanks,

-Henri

Hi,
when i use FlexibleOptionGroup add-on (version 2.3) with Vaadin 7.6.6 under OSGi server (Virgo Server) i get the following error:

[code]

Caused by: java.lang.NoClassDefFoundError: com/vaadin/shared/communication/SharedState
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at com.vaadin.server.AbstractClientConnector.findStateType(AbstractClientConnector.java:318)
at com.vaadin.server.AbstractClientConnector.getStateType(AbstractClientConnector.java:305)
at com.vaadin.server.AbstractClientConnector.createState(AbstractClientConnector.java:289)
at com.vaadin.server.AbstractClientConnector.getState(AbstractClientConnector.java:253)
at com.vaadin.ui.AbstractComponent.getState(AbstractComponent.java:751)
at com.vaadin.ui.AbstractField.getState(AbstractField.java:1723)
at org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroup.getState(FlexibleOptionGroup.java:169)
at org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroup.getState(FlexibleOptionGroup.java:42)
at com.vaadin.server.AbstractClientConnector.getState(AbstractClientConnector.java:236)
at com.vaadin.ui.AbstractComponent.getState(AbstractComponent.java:746)
at com.vaadin.ui.AbstractField.getState(AbstractField.java:1718)
at com.vaadin.ui.AbstractSelect.getState(AbstractSelect.java:2339)

Caused by: org.eclipse.virgo.kernel.osgi.framework.s: com.vaadin.shared.communication.SharedState in KernelBundleClassLoader: [bundle=hu.xxx.yyy.web_1.0.0.BUILD-SNAPSHOT]

at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 143 common frames omitted

Caused by: java.lang.ClassNotFoundException: com.vaadin.shared.communication.SharedState
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:146)
… 144 common frames omitted
[/code]What did I wrong? Could anyone help me? Thanks in advance!


Update:
when I imported both com.vaadin.server and com.vaadin.shared bundle, then I got the following exception:

java.lang.RuntimeException: org.eclipse.virgo.kernel.osgi.framework.ImportMergeException: cannot merge imports of package 'com.google.gwt.core' from sources 'Import-Library 'org.springframework.spring' version '3.1.3.RELEASE'(null), Import-Bundle 'com.vaadin.server' version '7.6.6', Import-Bundle 'com.vaadin.shared' version '7.6.6'' because of conflicting values 'com.vaadin.shared', 'com.vaadin.server' of attribute 'bundle-symbolic-name' After I made a little investigation I relalized that both com.vaadin.shared and com.vaadin.server jar have the same base package name: com.google.gwt.core and that’s the problem for OSGi.

So I imported the whole com.vaadin.shared bundle (this bundle has more packages) and I imported all the packages of com.vaadin.server. So I have a big manifest.mf, but it seems to work at the moment.

Hi again!

My next problem with FlexibleOptionGroup is when i redeploy my webapp to the Virgo server (OSGi) I always get the following error, when i click the option item component:
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class …

Every first deploy with newly started server it works fine, but when i redeploy, i always got the following IllegalArgumentException.
Related ticket is here:
https://dev.vaadin.com/ticket/12826#comment:6

But I don’t understand how should i use FlexibleOptionGroup in order not to receiver that error?. Or forget add-ons on OSGi server and use only built-in components?
Any help would be great, thanks!