populateRequest(theRequest);
}
public void testELSet() throws Exception
{
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
ValueExpression valueExpression = null;
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
Map myMap = new HashMap();
TestBean myBean = new TestBean();
myMap.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
//
// Set tests
//
valueExpression = this.create("myMap.myBean.one");
valueExpression.setValue(getFacesContext().getELContext(), "one");
Map map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set null as the value
valueExpression = this.create("myMap.myBean.prop");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("myMap[\"myBean\"].one");
valueExpression.setValue(getFacesContext().getELContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set the property to null
valueExpression = this.create("myMap[\"myBean\"].prop");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
String msg = "Default Message";
if (((TestBean) map.get("myBean")).getProp() != null)
{
msg = ((TestBean) map.get("myBean")).getProp().getClass().getName();
}
assertEquals(msg, null, ((TestBean) map.get("myBean")).getProp());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("myMap.myBean['one']");
valueExpression.setValue(getFacesContext().getELContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// set the prop to null
valueExpression = this.create("myMap.myBean['prop']");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("NonExist");
valueExpression.setValue(getFacesContext().getELContext(), "value");