org.beangle.struts2.view.component.Radios Maven / Gradle / Ivy
/*
* Beangle, Agile Development Scaffold and Toolkit
*
* Copyright (c) 2005-2014, Beangle Software.
*
* Beangle is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Beangle is distributed in the hope that it will be useful.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Beangle. If not, see .
*/
package org.beangle.struts2.view.component;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.beangle.commons.collection.CollectUtils;
import org.beangle.commons.lang.Strings;
import com.opensymphony.xwork2.util.ValueStack;
/**
* Radio group
*
* @author chaostone
* @since 2.4
*/
public class Radios extends UIBean {
private String name;
private String label;
private Object items;
private Radio[] radios;
private Object value;
private String comment;
public Radios(ValueStack stack) {
super(stack);
}
@Override
protected void evaluateParams() {
if (null == this.id) generateIdIfEmpty();
label=processLabel(label,name);
List> keys = convertItems();
radios = new Radio[keys.size()];
int i = 0;
for (Object key : keys) {
radios[i] = new Radio(stack);
radios[i].setTitle(String.valueOf(((Map, ?>) items).get(key)));
radios[i].setValue(key);
radios[i].setId(Strings.concat(this.id + "_" + String.valueOf(i)));
radios[i].evaluateParams();
i++;
}
if (null == this.value && radios.length > 0) this.value = radios[0].getValue();
this.value = Radio.booleanize(this.value);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List> convertItems() {
if (items instanceof Map) return CollectUtils.newArrayList(((Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy