tags:

views:

748

answers:

2

Hi,

I am running into issues with passing parameters to managed beans in JSP within Oracle ADF. Here is an example JSP test page I am trying to pass parameters to a test method in a POJO:

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich"&gt;
  <jsp:directive.page contentType="text/html;charset=windows-1252"/>
  <f:view>
    <af:document title="Automated Scheduling Tool > Customer Portal > Packages"
                 id="d1">
      <af:messages id="m1"/>
      <af:form id="f1">
        <center>
          <br/><br/><br/>
          <table cellspacing="0" cellpadding="45" width="800">
            <tr>
              <td width="100%" class="darkBackground">
                <span class="largeTitle">AUTOMATED SCHEDULING TOOL</span>                 
                <br/>                 
                <span class="mediumTitle">CUSTOMER PORTAL</span>
              </td>
            </tr>
            <tr>
                <af:outputText value="#{pageFlowScope.customerFacadeBean.test['test1', 'test2']}" id="ot1" />
            </tr>
          </table>
        </center>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

public class CustomerFacade {
    private final PackageMapper mapper;
    private List<Package> packages;

    public CustomerFacade() {
        mapper = new PackageMapper();
        packages = mapper.findAllPackages();
    }

    public List<Package> getPackages() {
        return packages;
    }


    public String test(String testString1, String testString2){
        System.out.println(testString1 + testString2);
        return "Success!";
    }
}

Does anyone have any suggestions for how I can pass parameters to the POJO via a managed bean?

+1  A: 
#{pageFlowScope.customerFacadeBean.test['test1', 'test2']}

This is not a legal Unified Expression Language expression. You could probably do something like this:

#{pageFlowScope.customerFacadeBean.test['test1']['test2']}

...where test resolved to a map of maps:

  public Map<Object, Map<Object, Object>> getTest() {
    return new HashMap<Object, Map<Object, Object>>() {
      @Override
      public Map<Object, Object> get(final Object test1) {
        return new HashMap<Object, Object>() {
          @Override
          public Object get(Object test2) {
            return getSomething(test1, test2);
          }
        };
      }
    };
  }

  private Object getSomething(Object test1, Object test2) {
    //TODO
  }

Obviously, this is really ugly.

You could try implementing a custom function in the form #{stuff:callTest(pageFlowScope.customerFacadeBean, 'test1', 'test2')}.

Servers implementing JSP 2.1 Maintenance Release 2 should support expressions of the form #{mybean.something(param)} (read this for more info). Some frameworks may already support this syntax - it's worth checking the doc.

McDowell
A: 

There is a somewhat elegant alternative solution similar to the above: http://wiki.apache.org/myfaces/Parameters_In_EL_Functions

BestPractices