Liferay <portlet:actionURL>

See*_*a K 7 java tags jsp liferay liferay-6

在我的jsp中,我有以下代码:

<portlet:actionURL name="addDetails" var="addDetailsURL" />
<aui:form name="addDetails" action="<%=addDetailsURL.toString() %>" method="post" >
        <aui:input type="text" label="name:" name="name" value="" />
        <aui:input type="text" label="surname:" name="surname" value="" />
        <aui:input type="text" label="age:" name="age" value="" />
        <aui:button type="submit" value="addDetails" />
</aui:form>
Run Code Online (Sandbox Code Playgroud)

我正在使用liferay.我想提交这些将在java类中处理的数据.我的java类功能很少.我应该如何在上面的jsp中指定它应该在提交表单后访问java中的特定函数?

per*_*erp 14

如果您的portlet继承MVCPortlet,只需创建一个与actionURL具有相同"名称"的公共方法,它接受一个ActionRequestActionResponse参数:

public void addDetails(ActionRequest req, ActionResponse rsp) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)


Dan*_*ani 9

仅供记录,您还可以使用注释.例如,你有这个jsp:

<portlet:actionURL var="urlAction">
    <portlet:param name="javax.portlet.action" value="myAction"/>
</portlet:actionURL>

<aui:form action="${urlAction}" method="post">
    <aui:input type="text" label="name:" name="name" value="" />
    <aui:button type="submit" value="Submit" />
</aui:form>
Run Code Online (Sandbox Code Playgroud)

这个Java方法在你的MVCPortlet:

@ProcessAction(name = "myAction")
public void method(ActionRequest actionRequest, ActionResponse actionResponse) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)


kay*_*yz1 6

如果您只想处理一个操作:

门户

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
{
    // TODO Auto-generated method stub
    super.processAction(actionRequest, actionResponse);
}
Run Code Online (Sandbox Code Playgroud)

JSP

<form action="<portlet:actionURL />" method="post">
    <aui:button type="submit" value="addDetails" />
</form>
Run Code Online (Sandbox Code Playgroud)

如果您需要多个操作方法:

public void myAction(ActionRequest request, ActionResponse response)
{
     Long id = ParamUtil.getLong(request, "myParam");
     // TODO
}
Run Code Online (Sandbox Code Playgroud)

JSP

<portlet:actionURL name="myAction" var="myActionVar">
    <portlet:param name="myParam" value="${currentElement.id}"></portlet:param>
</portlet:actionURL>

<a href="${myActionVar}">Click Me!</a>
Run Code Online (Sandbox Code Playgroud)

但你可能会这样做:

门户

@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException
{
    String action = request.getParameter("action");

    if(action.equalsIgnoreCase("myAction")){
        // handle AJAX call
    }
}
Run Code Online (Sandbox Code Playgroud)

JSP

<portlet:resourceURL var="resourceUrl" />
<input id="resourceURL" type="hidden" value="${resourceUrl}" />
Run Code Online (Sandbox Code Playgroud)

JavaScript的

$.post($('#resourceURL').val(),{
    action : 'myAction'
}).done(function(result){
    alert('Action completed successfully!')
});
Run Code Online (Sandbox Code Playgroud)