OptionGroup inside Table

Hi guys,
Is possible use OptionGroup in combination with table? I need a table with inside a OptionGroup but I had no luck to do it… The idea is to have an Item per row…

I’m trying to do something like that…


          Table table = new Table();
            table.setSizeFull();
            table.addContainerProperty("Name", String.class, null);
            table.addContainerProperty("Value", Item.class, null);
            List<String> list=getList();
    		OptionGroup og = new OptionGroup(null, list);
	
    		
    		int a=1;
    		for (String elem: list){
    			table.addItem(new Object[] {"Name_"+a, og.getItem(elem)}, new Integer(a));
    			a++;
    		}


I tried also with this:


for (Object elem: og.getItemIds()){
    			table.addItem(new Object[] {"Name_"+a, og.getItem(elem)}, new Integer(a));
    			a++;
    		}

with no luck!!!

I’m beginning to think it’s not possible to do…

Thanks again

Hi.

Try this:

	final VerticalLayout vl = new VerticalLayout();
	vl.setSizeUndefined();
	this.setContent(vl);
	vl.addComponent(btn);
	
	
	Table table = new Table();
	vl.addComponent(table);
	
	table.addContainerProperty("Description", String.class, "default");
	table.addGeneratedColumn("Choose value", new Table.ColumnGenerator() {
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			// TODO Auto-generated method stub
			OptionGroup og = new OptionGroup("optionCaption");
			og.addItem("1");
			og.addItem("2");
			og.addItem("3");
			return og;
		}
	});
	table.addItem(new Object[]{"Option 1"}, null);
	table.addItem(new Object[]{"Option 2"}, null);

Thanks very much for the answer…

But is not what I was looking for : Your example show the whole optionGroup in a row… What I need is a single checkbox in any rows and the possibility to use the events to permit an action in which when I click to one of those checkboxes, another one or many other in the others rows is disable…
I hope I was more clear this time…

final VerticalLayout vl = new VerticalLayout();
vl.setSizeUndefined();
this.setContent(vl);
vl.addComponent(btn);

	Table table = new Table();
	vl.addComponent(table);
	
	final List<CheckBox> cboxes = new ArrayList<CheckBox>();
	table.addContainerProperty("Description", String.class, "default");
	table.addGeneratedColumn("Choose value", new Table.ColumnGenerator() {
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			// TODO Auto-generated method stub
			CheckBox ch = new CheckBox("checkBox");
			cboxes.add(ch);
			ch.addListener(new Listener() {
				@Override
				public void componentEvent(Event event) {
					for (CheckBox cb : cboxes){
						if (!event.getComponent().equals(cb))
							cb.setEnabled(!((CheckBox)event.getComponent()).getValue());
					}
				}
			});
			return ch;
		}
	});
	table.addItem(new Object[]{"Option 1"}, null);
	table.addItem(new Object[]{"Option 2"}, null);
	table.addItem(new Object[]{"Option 3"}, null);
	table.addItem(new Object[]{"Option 4"}, null);

Check out my
FlexibleOptionGroup
add-on.

@ Henri : Thank you very much this is what I was searching for…

@Peter: thank you again, with CheckBox is ok… I know… But my problem was to use optionGroup, and without plug-in seems to be impossible to do what I was looking for…

Have a nice day :wink: