oracle ADF:通过 JSP 中的托管 bean 调用方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1695492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:23:18  来源:igfitidea点击:

ADF: Calling a method through a managed beans in JSP

javaoraclejspx

提问by jds2501

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:

我在将参数传递给 Oracle ADF 中 JSP 中的托管 bean 时遇到了问题。这是一个示例 JSP 测试页面,我试图将参数传递给 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">
  <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?

有没有人对我如何通过托管 bean 将参数传递给 POJO 有任何建议?

回答by McDowell

#{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 testresolved to a map of maps:

...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
  }

Obviously, this is really ugly.

显然,这真的很丑陋。

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

您可以尝试在表单中实现自定义函数#{stuff:callTest(pageFlowScope.customerFacadeBean, 'test1', 'test2')}

Servers implementing JSP 2.1 Maintenance Release 2should 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.

实现JSP 2.1 维护版本 2 的服务器应该支持表单的表达式#{mybean.something(param)}阅读这里了解更多信息)。一些框架可能已经支持这种语法 - 值得查看文档。

回答by BestPractices

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

有一个类似于上述的优雅的替代解决方案:http: //wiki.apache.org/myfaces/Parameters_In_EL_Functions