问题描述
我只想知道,如果我可以在一个jsp中有两个< portlet:actionURL var =唤醒>
动作网址。这将根据填充的输入和JS提交此表单来调用。例如:
JS:
函数startActions(){
if(document.getElementById(shut)。checked ||
document.getElementById(reboot)。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文档:
因此,基于适当的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 {
//您的唤醒逻辑到达
}
$ c $但是,没有必要将两个表单/动作库放在一起,你可以通过实现一个动作来实现你的需求方法在侦听器类中,根据参数的值进行过滤。
在每个操作中,该参数将标识已调用哪个操作。
模式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:
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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!