开发者

How do you make an ATG droplet serve a default oparam

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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜