两个操作URL在一个jsp中 [英] Two action URLs in one jsp

查看:145
本文介绍了两个操作URL在一个jsp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道,如果我可以在一个jsp中有两个< portlet:actionURL var =唤醒> 动作网址。这将根据填充的输入和JS提交此表单来调用。例如:

JS:

 函数startActions(){
if(document.getElementById(shut)。checked ||
document.getElementById(rebo​​ot)。checked){
document.getElementById(shutdownRebootForm )。提交();

if(document.getElementById(wake)。checked){
document.getElementById(wakeUpForm)。submit();


HTML: p>

 < portlet:actionURL var =shutdownReboot> 
< portlet:param name =actionvalue =shutdown-reboot/>
< / portlet:actionURL>
< form id =shutdownRebootFormmethod =postaction =$ {shutdownReboot}>
//一些HTML代码
< / form>

< portlet:actionURL var =唤醒>
< portlet:param name =wakeactionvalue =唤醒/>
< / portlet:actionURL>
< form id =wakeUpFormmethod =postaction =$ {wakeup}>
//一些HTML代码
< / form>

我正在使用spring MVC ...这可能实现吗?它会如预期的那样工作吗?

解决方案

Liferay文档


您可以在portlet中执行任意多的操作。实现每个
一个作为接收两个参数的方法:一个 ActionRequest 和一个
ActionResponse 。为任何你想要的方法命名方法,但是请注意,
方法名称必须匹配指向它的URL名称。


因此,基于适当的JSP,动作和脚本结构,您可以将多个actionURL放置在单个portlet中。重要的一点是要将URL标记上指定的 name 属性的值与方法名称匹配。



如果你是指定name属性,那么你需要在监听器类中实现单独的动作方法。



模式1: / p>

 < portlet:actionURL var =shutdownRebootURLname =shutdownReboot> 
< portlet:param name =actionvalue =shutdown-reboot/>
< / portlet:actionURL>

< portlet:actionURL var =wakeupURLname =唤醒>
< portlet:param name =wakeactionvalue =唤醒/>
< / portlet:actionURL>

因此,您的操作类应该包含以下方法:
$ b $公共无效shutdownReboot(ActionRequest actionRequest,ActionResponse actionResponse)
抛出IOException,PortletException {
//您的shutdownReboot逻辑转到这里
}

public void wakeup(ActionRequest actionRequest,ActionResponse actionResponse)
抛出IOException异常,PortletException {
//您的唤醒逻辑到达
}
在每个操作中,该参数将标识已调用哪个操作。



模式2:



请考虑以下示例:

HTML:

 < form action =< portlet:actionURL />方法= POST > 
< input type =hiddenname =actionid =actionvalue =/>

< table>
< tr>
< td>关机复选框< / td>
< td>重新启动复选框< / td>
< td>唤醒复选框< / td>
< / tr>
< tr>
< td>
<! - 基于复选框显示特定按钮 - >
< button type =submitid =shutdownRebootonclick =startActions('shutdownReboot');> Shutdown / Reboot< / button>
< button type =submitid =wakeuponclick =startActions('wakeup');>唤醒< /按钮>
< / td>
< / tr>
< / table>
< / form>

Javascript:

 函数startActions(action){
document.getElementById('action')。value = action;
/ *设置其他必需的参数* /
}

方法:

  String action =; 
public void processAction(ActionRequest actionRequest,ActionResponse actionResponse)
抛出IOException,PortletException {

if(actionRequest.getParameter(action)!= null&& actionRequest。 getParameter(action)!=){
action = actionRequest.getParameter(action);


if(action.equals(shutdownReboot)){
// shutdown-reboot logic
} else if(action.equals(wakeup )){
//唤醒逻辑
} else {
//默认逻辑
}
}


I just want to know, if I can have two <portlet:actionURL var="wakeup"> action urls in one jsp. Which will be called depending on a filled inputs and JS submiting this forms. Example:

JS:

function startActions() {
    if (document.getElementById("shut").checked ||
        document.getElementById("reboot").checked) {    
        document.getElementById("shutdownRebootForm").submit();
    }
    if (document.getElementById("wake").checked) {
        document.getElementById("wakeUpForm").submit();
    }
}

HTML:

<portlet:actionURL var="shutdownReboot">
    <portlet:param name="action" value="shutdown-reboot" />
</portlet:actionURL>
<form id="shutdownRebootForm" method="post" action="${shutdownReboot}">
    //some HTML code
</form>

<portlet:actionURL var="wakeup">
    <portlet:param name="wakeaction" value="wakeup" />
</portlet:actionURL>
<form id="wakeUpForm" method="post" action="${wakeup}">
    //some HTML code
</form> 

I'm using spring MVC... is this possible to implement? Will it work as expected?

解决方案

Liferay Documentation:

You can have as many actions as you want in a portlet. Implement each one as a method that receives two parameters: an ActionRequest and an ActionResponse. Name the method whatever you want, but note that the method name must match the URL name that points to it.

Therefore, based on suitable JSP, action and scripting structure, you can place as many actionURLs, you want in a single portlet. The important point is to match the value of name attribute specified on URL tag with method's name.

If you are specifying name attribute, then you need to implement separate action methods in listener class.

Pattern 1:

See, your actionURLs will look like following:

<portlet:actionURL var="shutdownRebootURL" name="shutdownReboot">
    <portlet:param name="action" value="shutdown-reboot" />
</portlet:actionURL>

<portlet:actionURL var="wakeupURL" name="wakeup">
    <portlet:param name="wakeaction" value="wakeup" />
</portlet:actionURL>

So, your action slass should contain following methods:

public void shutdownReboot(ActionRequest actionRequest, ActionResponse actionResponse)
    throws IOException, PortletException {
        // Your shutdownReboot logic goes here
}

public void wakeup(ActionRequest actionRequest, ActionResponse actionResponse)
    throws IOException, PortletException {
        // Your wakeup logic goes here
}

However, there is no hard-n-fast need to put two form(s) / actionURLs, you can achieve your requirement by implementing one action method in listener class, filtered based on the parameter's value. On each action, that parameter will identify, which action has been called.

Pattern 2:

Consider following example:

HTML:

<form action="<portlet:actionURL />" method="post">
    <input type="hidden" name="action" id="action" value="" />

    <table>
        <tr>
            <td>shutdown checkbox</td>
            <td>reboot checkbox</td>
            <td>wakeup checkbox</td>
        </tr>
        <tr>
            <td>
                <!-- show specific button based on checkbox checked -->
                <button type="submit" id="shutdownReboot" onclick="startActions('shutdownReboot');">Shutdown / Reboot</button>
                <button type="submit" id="wakeup" onclick="startActions('wakeup');">Wakeup</button>
            </td>
        </tr>
    </table>
</form>

Javascript:

function startActions(action) {
    document.getElementById('action').value = action;
    /* set other required parameters */
}

Action method:

String action = "";
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    if(actionRequest.getParameter("action") != null && actionRequest.getParameter("action") != ""){
            action = actionRequest.getParameter(action);
    }

    if(action.equals("shutdownReboot")){
        // shutdown-reboot logic
    }else if(action.equals("wakeup")){
        // wakeup logic
    }else{
        // default logic
    }       
}

这篇关于两个操作URL在一个jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆