public void processRender(WebuiRequestContext context) throws Exception { ResourceBundle res = context.getApplicationResourceBundle(); UIForm uiForm = getAncestorOfType(UIForm.class); String formId = null; if (uiForm.getId().equals("UISearchForm")) formId = uiForm.<UIComponent>getParent().getId(); else formId = uiForm.getId(); Writer w = context.getWriter(); w.write("<select class=\"selectbox\" name=\""); w.write(name); w.write("\""); if (onchange_ != null) { w.append(" onchange=\"").append(renderOnChangeEvent(uiForm)).append("\""); } if (isMultiple_) w.write(" multiple=\"true\""); if (size_ > 1) w.write(" size=\"" + size_ + "\""); if (isDisabled()) w.write(" disabled "); renderHTMLAttributes(w); w.write(">\n"); for (SelectItem item : options_) { String label = item.getLabel(); if (item instanceof SelectOption) { try { label = res.getString(formId + ".label.option." + ((SelectOption) item).getValue()); } catch (MissingResourceException ex) { } w.write(renderOption(((SelectOption) item), label)); } else if (item instanceof SelectOptionGroup) { label = item.getLabel(); try { label = res.getString(getFrom().getId() + ".optionGroup.label." + label); } catch (MissingResourceException ex) { log.debug("Could not find: " + getFrom().getId() + ".optionGroup.label." + label); } w.write("<optgroup label=\""); w.write(label); w.write("\">\n"); for (SelectOption opt : ((SelectOptionGroup) item).getOptions()) { label = opt.getLabel(); try { label = res.getString(formId + ".label.option." + opt.getValue()); } catch (MissingResourceException ex) { } w.write(renderOption(opt, label)); } w.write("</optgroup>\n"); } } w.write("</select>\n"); if (this.isMandatory()) w.write(" *"); }
private String renderOption(SelectOption option, String label) { StringBuffer buf = new StringBuffer(); buf.append("<option value=\""); buf.append(option.getValue()); buf.append("\""); if (option.isSelected()) buf.append("selected=\"selected\""); buf.append(">"); buf.append(label); buf.append("</option>\n"); return buf.toString(); }
public UIFormSelectBoxWithGroups setValue(String value) { value_ = value; for (SelectItem option : options_) { if (option instanceof SelectOption) { if (((SelectOption) option).getValue().equals(value_)) ((SelectOption) option).setSelected(true); else ((SelectOption) option).setSelected(false); } else if (option instanceof SelectOptionGroup) { ((SelectOptionGroup) option).setValue(value); } } return this; }
public UIFormSelectBoxWithGroups setSelectedValues(String[] values) { for (SelectItem option : options_) { if (option instanceof SelectOption) { ((SelectOption) option).setSelected(false); for (String value : values) { if (value.equals(((SelectOption) option).getValue())) { ((SelectOption) option).setSelected(true); break; } } } else if (option instanceof SelectOptionGroup) { ((SelectOptionGroup) option).setSelectedValue(values); } } return this; }
@Override public void reset() { // TODO Auto-generated method stub - dang.tung if (options_ == null || options_.size() < 1) return; for (SelectItem option : options_) { if (option instanceof SelectOption) ((SelectOption) option).setSelected(false); else if (option instanceof SelectOptionGroup) { ((SelectOptionGroup) option).reset(); } } for (SelectItem option : options_) { if (option instanceof SelectOption) { value_ = ((SelectOption) option).getValue(); ((SelectOption) option).setSelected(true); break; } } }
@SuppressWarnings("unused") public void decode(Object input, WebuiRequestContext context) throws Exception { String[] values = context.getRequestParameterValues(getId()); if (values == null) { value_ = null; for (SelectItem option : options_) { if (option instanceof SelectOption) ((SelectOption) option).setSelected(false); else if (option instanceof SelectOptionGroup) { for (SelectOption opt : ((SelectOptionGroup) option).getOptions()) { opt.setSelected(false); } } } return; } int i = 0; value_ = values[0]; for (SelectItem item : options_) { if (item instanceof SelectOption) { if (i > -1 && ((SelectOption) item).getValue().equals(values[i])) { ((SelectOption) item).setSelected(true); if (values.length == ++i) i = -1; } else ((SelectOption) item).setSelected(false); } else if (item instanceof SelectOptionGroup) { for (SelectOption opt : ((SelectOptionGroup) item).getOptions()) { if (i > -1 && ((SelectOption) opt).getValue().equals(values[i])) { ((SelectOption) opt).setSelected(true); if (values.length == ++i) i = -1; } else { ((SelectOption) opt).setSelected(false); } } } } }