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

发布于 2024-08-10 14:36:28 字数 1971 浏览 6 评论 0原文

我在向 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!";
    }
}

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

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">
  <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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱格式化 2024-08-17 14:36:28
#{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
  }

显然,这真的很难看。

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

实现 JSP 2.1 Maintenance Release 2 的服务器应该支持以下表达式形式#{mybean.something(param)} (阅读本文以获取更多信息)。一些框架可能已经支持这种语法 - 值得检查文档。

#{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.

小红帽 2024-08-17 14:36:28

有一个类似于上面的优雅的替代解决方案: http://wiki.apache.org/myfaces/ EL函数中的参数

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文