如何让 ATG Droplet 提供默认的 oparam

发布于 2024-11-09 10:02:34 字数 896 浏览 0 评论 0原文

在 ATG 中,如果其他条件均不满足,则 Switch Droplet 将转到默认 oparam。

我有一个 Droplet,我想表现得类似。您可以在页面上调用它并将代码放入 oparam 条件内。如果您没有从 Droplet 返回的 oparam 的情况,则它应该采用默认值。

droplet.java

public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) 
    throws ServletException, IOException
{
    String b = (String) request.getParameter("a");
    if(b != null && b.equals("c")){
        request.serviceLocalParameter("d", request, response);
    }else{
        request.serviceLocalParameter("e", request, response);
    }
}



droplet.jsp

<dsp:droplet name="Droplet">
    <dsp:oparam name="d">
        <!-- d param was set -->
    </dsp:oparam>
    <dsp:oparam name="default">
        <!-- e, or some other param was set -->
    </dsp:oparam>
</dsp:droplet>

我对 ATG 有点陌生,所以我可能会以错误的方式处理这个问题......

In ATG, the Switch droplet will go to the default oparam if none of the other conditions are met.

I have a droplet that I want to behave similarly. You call it on your page and put code inside of oparam conditions. If you don't have an case for the oparam that is returned from your droplet, it should just go to the default.

droplet.java

public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) 
    throws ServletException, IOException
{
    String b = (String) request.getParameter("a");
    if(b != null && b.equals("c")){
        request.serviceLocalParameter("d", request, response);
    }else{
        request.serviceLocalParameter("e", request, response);
    }
}



droplet.jsp

<dsp:droplet name="Droplet">
    <dsp:oparam name="d">
        <!-- d param was set -->
    </dsp:oparam>
    <dsp:oparam name="default">
        <!-- e, or some other param was set -->
    </dsp:oparam>
</dsp:droplet>

I'm somewhat new to ATG, so I might be going about this the wrong way...

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

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

发布评论

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

评论(1

惟欲睡 2024-11-16 10:02:34

如果您尝试为不存在的本地参数提供服务,serviceLocalParameter 将返回 false。所以你所要做的就是检查 serviceLocalParameter() 返回的值,如果它是 false,你就可以服务任意数量的不同的任意本地参数。在下面的示例中,我服务于任意参数“default”(注意:默认值是任意的,它可以被称为任何东西。如果我有一个oparam“foo”和一个oparam“bar”和一个oparam“beh”我可以尝试service foo,如果失败,我可以尝试服务 bar,如果失败,我可以尝试服务 beh...)

因此,应用于您的示例,以下内容将执行您想要的操作:

droplet.java

public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) 
    throws ServletException, IOException
{
    boolean handled = false;
    String b = (String) request.getParameter("a");

    if(b != null && b.equals("c")){
        handled = request.serviceLocalParameter("d", request, response);
    }else{
        handled = request.serviceLocalParameter("e", request, response);
    }

    /*
     * Did not find a valid parameter, try servicing the
     * parameter named "default" instead
     */
    if (!handled) {
        request.serviceLocalParameter("default", request, response);
    }
}

一个更简化的版本用于说明目的(仅包含与默认服务相关的代码):

boolean handled = false; 

handled = request.serviceLocalParameter("nondefault", request, response);

if (!handled) {
    handled = request.serviceLocalParameter("default", request, response);
}

If you try and service a non-existent local parameter, the serviceLocalParameter will return false. So all you have to do is check the value returned by serviceLocalParameter(), if it is false, you can service any number of different arbitrary local parameters. In the example below, I service the arbitrary parameter "default" (NOTE: default is ARBITRARY, it could be called anything. If I had an oparam "foo" and an oparam "bar" and an oparam "beh" I could try and service foo, if that failed, I could try and service bar and if that failed I could try and service beh...)

So, applied to your example, the following would do what you want:

droplet.java

public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) 
    throws ServletException, IOException
{
    boolean handled = false;
    String b = (String) request.getParameter("a");

    if(b != null && b.equals("c")){
        handled = request.serviceLocalParameter("d", request, response);
    }else{
        handled = request.serviceLocalParameter("e", request, response);
    }

    /*
     * Did not find a valid parameter, try servicing the
     * parameter named "default" instead
     */
    if (!handled) {
        request.serviceLocalParameter("default", request, response);
    }
}

A more simplified version of this for illustrative purposes (with only the code relevant to serving default):

boolean handled = false; 

handled = request.serviceLocalParameter("nondefault", request, response);

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