public void beforeResult(ActionInvocation invocation, String resultCode) {
      ValueStack stack = invocation.getStack();
      CompoundRoot root = stack.getRoot();

      boolean needsRefresh = true;
      Object newModel = action.getModel();

      // Check to see if the new model instance is already on the stack
      for (Object item : root) {
        if (item.equals(newModel)) {
          needsRefresh = false;
        }
      }

      // Add the new model on the stack
      if (needsRefresh) {

        // Clear off the old model instance
        if (originalModel != null) {
          root.remove(originalModel);
        }
        if (newModel != null) {
          stack.push(newModel);
        }
      }
    }
Example #2
0
  public void testGetTopTarget() throws Exception {
    Foo foo = new Foo();
    Map context = Ognl.createDefaultContext(foo);

    CompoundRoot root = new CompoundRoot();
    Object top = ognlUtil.getRealTarget("top", context, root);
    assertEquals(root, top); // top should be root

    root.push(foo);
    Object val = ognlUtil.getRealTarget("unknown", context, root);
    assertNull(val); // not found
  }