@Test public void withItemsNullReference() throws Exception { getPageContext().setAttribute( SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems(Collections.emptyList()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); List children = rootElement.elements(); assertEquals("Incorrect number of children", 0, children.size()); }
floats.add(new Float("12.35")); this.tag.setItems(floats); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result);
@Test public void withCollection() throws Exception { getPageContext().setAttribute( SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); this.tag.setId("myOption"); this.tag.setCssClass("myClass"); this.tag.setOnclick("CLICK"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); List children = rootElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element element = (Element) rootElement.selectSingleNode("option[@value = 'UK']"); assertEquals("UK node not selected", "selected", element.attribute("selected").getValue()); assertEquals("myOption3", element.attribute("id").getValue()); assertEquals("myClass", element.attribute("class").getValue()); assertEquals("CLICK", element.attribute("onclick").getValue()); }
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name");
private Tag createSelectTag( String expression, Map<String, String> attributes ) { // Select tag SelectTag select = new SelectTag(); // Empty option (if needed) if ( WidgetBuilderUtils.needsEmptyLookupItem( attributes ) ) { OptionTag emptyOption = new OptionTag(); emptyOption.setValue( "" ); JspUtils.addDeferredChild( select, emptyOption ); } // Options tag OptionsTag optionsTag = new OptionsTag(); optionsTag.setItems( expression ); // Optional itemValue and itemLabel String itemValue = attributes.get( SPRING_LOOKUP_ITEM_VALUE ); if ( itemValue != null ) { optionsTag.setItemValue( itemValue ); } String itemLabel = attributes.get( SPRING_LOOKUP_ITEM_LABEL ); if ( itemLabel != null ) { optionsTag.setItemLabel( itemLabel ); } JspUtils.addDeferredChild( select, optionsTag ); return select; }