两个操作 URL 合二为一 jsp
Two action URLs in one jsp
我只想知道,我是否可以在一个 jsp 中包含两个 <portlet:actionURL var="wakeup">
操作 url。将根据填写的输入和提交此表格的 JS 调用哪个。示例:
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>
我正在使用 spring MVC...这可以实现吗?它会按预期工作吗?
Liferay 文档:
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.
因此,基于合适的 JSP、操作和脚本结构,您可以在单个 portlet 中放置任意数量的操作URL。重点是将 URL 标记上指定的 name
属性值与方法名称相匹配。
如果您指定名称属性,则需要在侦听器中实现单独的操作方法class。
模式一:
看,您的操作URL将如下所示:
<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>
因此,您的操作类应包含以下方法:
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
}
然而,没有硬性的需要放置两个表单/动作URLs,你可以通过在监听器中实现一个动作方法来实现你的要求class,根据参数的值过滤。
对于每个操作,该参数将标识调用了哪个操作。
模式二:
考虑以下示例:
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 */
}
操作方法:
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
}
}
我只想知道,我是否可以在一个 jsp 中包含两个 <portlet:actionURL var="wakeup">
操作 url。将根据填写的输入和提交此表格的 JS 调用哪个。示例:
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>
我正在使用 spring MVC...这可以实现吗?它会按预期工作吗?
Liferay 文档:
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 anActionResponse
. Name the method whatever you want, but note that the method name must match the URL name that points to it.
因此,基于合适的 JSP、操作和脚本结构,您可以在单个 portlet 中放置任意数量的操作URL。重点是将 URL 标记上指定的 name
属性值与方法名称相匹配。
如果您指定名称属性,则需要在侦听器中实现单独的操作方法class。
模式一:
看,您的操作URL将如下所示:
<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>
因此,您的操作类应包含以下方法:
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
}
然而,没有硬性的需要放置两个表单/动作URLs,你可以通过在监听器中实现一个动作方法来实现你的要求class,根据参数的值过滤。 对于每个操作,该参数将标识调用了哪个操作。
模式二:
考虑以下示例:
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 */
}
操作方法:
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
}
}