Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* RadiogroupSelectedItemConverter.java
 
 {{IS_NOTE
 	Purpose:
 		
 	Description:
 		
 	History:
 		Mon Mar 12 11:05:43     2007, Created by Henri
}}IS_NOTE
Copyright (C) 2007 Potix Corporation. All Rights Reserved.
{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zkplus.databind;
Convert Radiogroup selected item to radio value and vice versa.

Deprecated:
As of release 7.0.0, replace with new ZK binding.
Author(s):
Henri
  	private static final long serialVersionUID = 200808191534L;
	public Object coerceToUi(Object valComponent comp) { //load
		if (val != null) {
			//iterate to find the selected radio via the value
			for (Iterator it = comp.getChildren().iterator(); it.hasNext();) {
				final Component child = (Component)it.next();
				if (child instanceof Radio) {
					if (val.equals(((Radio)child).getValue())) {
						return child;
					}
else if (!(child instanceof Radiogroup)) { //skip nested radiogroup
					//bug 2464484
					final Object value = coerceToUi(valchild); //recursive
					if (value != null) {
						return value;
					}
				}
			}
		}
		return null;
	}
  
	public Object coerceToBean(Object valComponent comp) { //save
 		return val != null ? ((Radio)val).getValue() : null;
	}
New to GrepCode? Check out our FAQ X