List of usage examples for org.springframework.web.servlet.tags.form SelectTag LIST_VALUE_PAGE_ATTRIBUTE
String LIST_VALUE_PAGE_ATTRIBUTE
To view the source code for org.springframework.web.servlet.tags.form SelectTag LIST_VALUE_PAGE_ATTRIBUTE.
Click Source Link
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithCollection() throws Exception { getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems("${countries}"); 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();/*w ww .j a va 2s . c o m*/ 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()); String hdivValue = this.confidentiality ? "2" : "UK"; Element element = (Element) rootElement.selectSingleNode("option[@value = '" + hdivValue + "']"); 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()); }
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithCollectionAndCustomEditor() throws Exception { PropertyEditor propertyEditor = new SimpleFloatEditor(); TestBean target = new TestBean(); target.setMyFloat(new Float("12.34")); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor); exposeBindingResult(errors);// w w w.j a v a2 s .c o m getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false)); this.tag.setItems("${floats}"); 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", 6, children.size()); Element element = (Element) rootElement.selectSingleNode("option[text() = '12.34f']"); assertNotNull("Option node should not be null", element); assertEquals("12.34 node not selected", "selected", element.attribute("selected").getValue()); assertNull("No id rendered", element.attribute("id")); element = (Element) rootElement.selectSingleNode("option[text() = '12.35f']"); assertNotNull("Option node should not be null", element); assertNull("12.35 node incorrectly selected", element.attribute("selected")); assertNull("No id rendered", element.attribute("id")); }
From source file:org.hdiv.web.servlet.tags.form.SelectTagTests.java
public void testWithNestedOptions() throws Exception { this.tag.setPath("country"); int result = this.tag.doStartTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, result); BindStatus value = (BindStatus) getPageContext().getAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE); assertEquals("Selected country not exposed in page context", "UK", value.getValue()); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.tag.doFinally(); String output = getWriter().toString(); assertTrue(output.startsWith("<select ")); assertTrue(output.endsWith("</select>")); assertContainsAttribute(output, "name", "country"); }
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithItemsNullReference() throws Exception { getPageContext().getRequest().removeAttribute("countries"); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItems("${countries}"); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); 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()); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagHDIV.java
@Override protected BindStatus getBindStatus() { return (BindStatus) this.pageContext.getAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE); }
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithoutItems() throws Exception { getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput();//from w ww . j a va2s .c om 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()); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java
public void testAsBodyTag() throws Exception { BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); String bodyContent = "some content"; this.tag.setValue("foo"); int result = this.tag.doStartTag(); assertEquals(BodyTag.EVAL_BODY_BUFFERED, result); this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter())); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); String output = getOutput();/* www .j av a 2 s . co m*/ assertOptionTagOpened(output); assertOptionTagClosed(output); assertContainsAttribute(output, "selected", "selected"); assertBlockTagContains(output, bodyContent); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java
public void testAsBodyTagSelected() throws Exception { BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); String bodyContent = "some content"; this.tag.setValue("Rob Harrop"); int result = this.tag.doStartTag(); assertEquals(BodyTag.EVAL_BODY_BUFFERED, result); this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter())); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); String output = getOutput();/* ww w . ja va 2 s . c o m*/ assertOptionTagOpened(output); assertOptionTagClosed(output); assertBlockTagContains(output, bodyContent); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java
public void testAsBodyTagCollapsed() throws Exception { BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); String bodyContent = "some content"; this.tag.setValue(bodyContent); int result = this.tag.doStartTag(); assertEquals(BodyTag.EVAL_BODY_BUFFERED, result); this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter())); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); String output = getOutput();/*from w w w . j a v a 2s . c om*/ assertOptionTagOpened(output); assertOptionTagClosed(output); String hdivValue = this.confidentiality ? "0" : bodyContent; assertContainsAttribute(output, "value", hdivValue); assertBlockTagContains(output, bodyContent); }
From source file:org.hdiv.web.servlet.tags.form.OptionTagTests.java
public void testAsBodyTagWithEditor() throws Exception { BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) { public PropertyEditor getEditor() { return new RulesVariantEditor(); }/*www . ja v a 2 s . c o m*/ }; getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant"); getPageContext().getRequest().setAttribute("rule", rulesVariant); this.tag.setValue("${rule}"); int result = this.tag.doStartTag(); assertEquals(BodyTag.EVAL_BODY_BUFFERED, result); assertEquals(rulesVariant, getPageContext().getAttribute("value")); assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue")); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); }