如何让 ATG Droplet 提供默认的 oparam
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试为不存在的本地参数提供服务,serviceLocalParameter 将返回 false。所以你所要做的就是检查 serviceLocalParameter() 返回的值,如果它是 false,你就可以服务任意数量的不同的任意本地参数。在下面的示例中,我服务于任意参数“default”(注意:默认值是任意的,它可以被称为任何东西。如果我有一个oparam“foo”和一个oparam“bar”和一个oparam“beh”我可以尝试service foo,如果失败,我可以尝试服务 bar,如果失败,我可以尝试服务 beh...)
因此,应用于您的示例,以下内容将执行您想要的操作:
一个更简化的版本用于说明目的(仅包含与默认服务相关的代码):
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:
A more simplified version of this for illustrative purposes (with only the code relevant to serving default):