如何在liferay ui选项卡中单击选项卡调用控制器方法?

时间:2012-06-19 05:38:50

标签: tabs liferay liferay-6

我在项目中使用了liferay ui标签。我想点击选项卡调用控制器。我使用portlerURL属性进行尝试,但它不起作用。

以下是我的代码段: -

view.jsp的

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>


<liferay-theme:defineObjects />
<portlet:defineObjects />


<liferay-portlet:renderURL var="portletURL" />

<%
    //We must Specify a default value for tabs. In this example it is sunday. Else it //will throw an error.
    String tabValue = ParamUtil.getString(request, "tab", "sunday");
    String tabsURL = "/" + tabValue.trim() + ".jsp";
    String tabNames = "Sunday,Monday,Tuesday";
    String tabVal = "sunday,monday,tuesday";
    if (permissionChecker.isCompanyAdmin(themeDisplay.getCompanyId())) {
        tabNames += ",Admin";
        tabVal += ",admin";
    }

    PortletURL URL = renderResponse.createActionURL();
    URL.setParameter("click","tabClick");
%>

<liferay-ui:tabs names="<%=tabNames%>" tabsValues="<%=tabVal%>" param="tab" url="<%= portletURL %>" />

<c:import url="<%= tabsURL %>"></c:import>

控制器: -

import com.liferay.util.bridges.mvc.MVCPortlet;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

/**
 * Portlet implementation class TabDemoPortlet
 */
public class TabDemoPortlet extends MVCPortlet {

    public void sunday(ActionRequest req,ActionResponse res) {
        System.out.println("Hello Sunday!!!");
    }

    public void monday(ActionRequest req,ActionResponse res) {
        System.out.println("Hello Monday!!!");
    }

    public void tuesday(ActionRequest req,ActionResponse res) {
        System.out.println("Hello Tuesday!!!");
    }
}

欢迎所有建议。在此先感谢!!!

1 个答案:

答案 0 :(得分:6)

您必须创建多个actionURL并在liferay-ui:tabs中使用它们。像这样的事情

<portlet:actionURL name="sunday" var ="sundayURL"/>
<portlet:actionURL name="monday" var ="mondayURL"/>
<portlet:actionURL name="tuesday" var ="tuesdayURL"/>

<liferay-ui:tabs names="<%=tabNames%>" 
   url0="<%=sundayURL/>"
   url1="<%=mondayURL/>"
   url2="<%=tuesdayURL/>"/>