@Override public String displaySearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context) { if (getDisplayType().equals("input")) { return super.displaySearch(name, prefix, criteria, context); } else if (getDisplayType().equals("radio") || getDisplayType().equals("checkbox")) { return displayRadioSearch(name, prefix, criteria, context); } else { return displaySelectSearch(name, prefix, criteria, context); } }
protected String displayRadioSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context) { StringBuffer buffer = new StringBuffer(); List<String> list = getList(context); List<String> selectlist = new ArrayList<String>(); /* * BaseProperty prop = (BaseProperty)object.safeget(name); if (prop==null) { selectlist = new ArrayList(); } * else if ((prop instanceof ListProperty)||(prop instanceof DBStringListProperty)) { selectlist = (List) * prop.getValue(); } else { selectlist = new ArrayList(); selectlist.add(prop.getValue()); } */ // Add options from Set for (Iterator<String> it = list.iterator(); it.hasNext();) { String rawvalue = it.next(); String value = getElementValue(rawvalue); String display = getDisplayValue(rawvalue, name, getMap(context), context); input radio = new input(getDisplayType().equals("radio") ? input.radio : input.checkbox, prefix + name, value); if (selectlist.contains(value)) { radio.setChecked(true); } radio.addElement(display); buffer.append(radio.toString()); if (it.hasNext()) { buffer.append("<br/>"); } } return buffer.toString(); }
@Override public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { if (getDisplayType().equals("input")) { input input = new input(); BaseProperty prop = (BaseProperty) object.safeget(name); if (prop != null) { input.setValue(prop.toFormString()); } input.setType("text"); input.setSize(getSize()); input.setName(prefix + name); input.setID(prefix + name); input.setDisabled(isDisabled()); buffer.append(input.toString()); } else if (getDisplayType().equals("radio") || getDisplayType().equals("checkbox")) { displayRadioEdit(buffer, name, prefix, object, context); } else { displaySelectEdit(buffer, name, prefix, object, context); } if (!getDisplayType().equals("input")) { org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, ""); buffer.append(hidden); } }
@Override public BaseProperty fromStringArray(String[] strings) { if (!isMultiSelect()) { return fromString(strings[0]); } BaseProperty prop = newProperty(); if (prop instanceof StringProperty) { return fromString(strings[0]); } List<String> list = new ArrayList<String>(); ((ListProperty) prop).setList(list); if (strings.length == 0) { return prop; } if ((strings.length == 1) && (getDisplayType().equals("input") || isMultiSelect())) { ((ListProperty) prop).setList(getListFromString(strings[0], getSeparators(), false)); return prop; } // If Multiselect and multiple results for (int i = 0; i < strings.length; i++) { String item = strings[i]; if (!item.trim().equals("")) { list.add(item); } } return prop; }
String value = getElementValue(rawvalue); input radio = new input((getDisplayType().equals("radio") && !isMultiSelect()) ? input.radio : input.checkbox, prefix + name, value); radio.setID("xwiki-form-" + name + "-" + count);