@Override public String getDesc(final Object option, final int index) { if (option == null) { return "Select one"; } else { return super.getDesc(option, index); } } };
/** * {@inheritDoc} */ @Override public String getDesc(final Object option, final int index) { CompareType type = (CompareType) option; switch (type) { case EQUAL: return "="; case NOT_EQUAL: return "!="; case LESS_THAN: return "<"; case LESS_THAN_OR_EQUAL: return "<="; case GREATER_THAN: return ">"; case GREATER_THAN_OR_EQUAL: return ">="; case MATCH: return "matches"; default: return super.getDesc(option, index); } } };
/** * Renders a single option within the dropdown. * * @param dropdown the dropdown being rendered. * @param option the option to render. * @param optionIndex the index of the option. OptionGroups are not counted. * @param html the XmlStringBuilder to paint to. * @param selectedOption the dropdown's selected option. * @param renderSelectionsOnly true to only render selected options, false to render all options. */ private void renderOption(final WDropdown dropdown, final Object option, final int optionIndex, final XmlStringBuilder html, final Object selectedOption, final boolean renderSelectionsOnly) { boolean selected = Util.equals(option, selectedOption); if (selected || !renderSelectionsOnly) { // Get Code and Desc String code = dropdown.getCode(option, optionIndex); String desc = dropdown.getDesc(option, optionIndex); // Check for null option (ie null or empty). Match isEmpty() logic. boolean isNull = option == null ? true : (option.toString().length() == 0); // Render option html.appendTagOpen("ui:option"); html.appendAttribute("value", code); html.appendOptionalAttribute("selected", selected, "true"); html.appendOptionalAttribute("isNull", isNull, "true"); html.appendClose(); html.appendEscaped(desc); html.appendEndTag("ui:option"); } }
@Test public void testDataList() throws IOException, SAXException, XpathException { WDropdown drop = new WDropdown(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE); assertSchemaMatch(drop); String code = drop.getCode(drop.getOptions().get(0), 0); String desc = drop.getDesc(drop.getOptions().get(0), 0); assertXpathEvaluatesTo("1", "count(//ui:dropdown/ui:option)", drop); assertXpathEvaluatesTo(desc, "//ui:dropdown/ui:option[@value='" + code + "']/text()", drop); assertXpathEvaluatesTo(drop.getListCacheKey(), "//ui:dropdown/@data", drop); }