2009-11-08 80 views
1

我遇到了将参数传递给Oracle ADF中的JSP中的托管bean的问题。下面是一个例子JSP测试页我想参数传递到测试方法的POJO:ADF:通过JSP中的托管bean调用方法

<?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"> 
    <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!"; 
    } 
} 

任何人都不会有如何,我可以通过托管bean参数传递给POJO有什么建议?

回答

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

这不是合法的统一表达式语言表达式。你也许可以做到这样的:

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

...其中test解析到地图的地图:

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 
    } 

显然,这是十分可怕的。

您可以尝试implementing a custom function的形式#{stuff:callTest(pageFlowScope.customerFacadeBean, 'test1', 'test2')}

实施JSP 2.1 Maintenance Release 2的服务器应支持表格#{mybean.something(param)}read this for more info)。一些框架可能已经支持这种语法 - 值得检查文档。