Search in sources :

Example 11 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testSetReallyDeepBarAsString.

public void testSetReallyDeepBarAsString() {
    Foo foo = new Foo();
    Foo foo2 = new Foo();
    foo.setChild(foo2);
    Foo foo3 = new Foo();
    foo2.setChild(foo3);
    OgnlValueStack vs = createValueStack();
    vs.push(foo);
    vs.setValue("child.child.bar", "bar:123");
    assertEquals("bar", foo.getChild().getChild().getBar().getTitle());
    assertEquals(123, foo.getChild().getChild().getBar().getSomethingElse());
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 12 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testFooBarAsString.

public void testFooBarAsString() {
    OgnlValueStack vs = createValueStack();
    Foo foo = new Foo();
    Bar bar = new Bar();
    bar.setTitle("blah");
    bar.setSomethingElse(123);
    foo.setBar(bar);
    vs.push(foo);
    assertEquals("blah:123", vs.findValue("bar", String.class));
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 13 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testSetDeepBarAsString.

public void testSetDeepBarAsString() {
    Foo foo = new Foo();
    Foo foo2 = new Foo();
    foo.setChild(foo2);
    OgnlValueStack vs = createValueStack();
    vs.push(foo);
    vs.setValue("child.bar", "bar:123");
    assertEquals("bar", foo.getChild().getBar().getTitle());
    assertEquals(123, foo.getChild().getBar().getSomethingElse());
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 14 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testPetSoarBug.

public void testPetSoarBug() {
    Cat cat = new Cat();
    cat.setFoo(new Foo());
    Bar bar = new Bar();
    bar.setTitle("bar");
    bar.setSomethingElse(123);
    cat.getFoo().setBar(bar);
    OgnlValueStack vs = createValueStack();
    vs.push(cat);
    assertEquals("bar:123", vs.findValue("foo.bar", String.class));
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 15 with OgnlValueStack

use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.

the class OgnlValueStackTest method testFindValueWithConversion.

public void testFindValueWithConversion() {
    // register converter
    TestBean2 tb2 = new TestBean2();
    OgnlValueStack stack = createValueStack();
    stack.push(tb2);
    Map myContext = stack.getContext();
    Map props = new HashMap();
    props.put("cat", "Kitty");
    ognlUtil.setProperties(props, tb2, myContext);
    // expect String to be converted into a Cat
    assertEquals("Kitty", tb2.getCat().getName());
    // findValue should be able to access the name
    Object value = stack.findValue("cat.name == 'Kitty'", Boolean.class);
    assertNotNull(value);
    assertEquals(Boolean.class, value.getClass());
    assertEquals(Boolean.TRUE, value);
    value = stack.findValue("cat == null", Boolean.class);
    assertNotNull(value);
    assertEquals(Boolean.class, value.getClass());
    assertEquals(Boolean.FALSE, value);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestBean2(com.opensymphony.xwork2.test.TestBean2) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)14 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)5 OgnlException (ognl.OgnlException)5 StrutsException (org.apache.struts2.StrutsException)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 ParseException (ognl.ParseException)4 TextProvider (com.opensymphony.xwork2.TextProvider)2 XWorkConverter (com.opensymphony.xwork2.conversion.impl.XWorkConverter)2 WrapperTemplateModel (freemarker.ext.util.WrapperTemplateModel)2 AdapterTemplateModel (freemarker.template.AdapterTemplateModel)2 TemplateBooleanModel (freemarker.template.TemplateBooleanModel)2 TemplateCollectionModel (freemarker.template.TemplateCollectionModel)2 TemplateHashModel (freemarker.template.TemplateHashModel)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 TemplateModelIterator (freemarker.template.TemplateModelIterator)2 TemplateNumberModel (freemarker.template.TemplateNumberModel)2