Laliwala IT Services

Laliwala IT Services
Website Development

Tuesday, February 22, 2011

How to create tabs in a portlet which is created through liferay sdk plugin, liferay sdk plugin, liferay 5.2.3 version, url.set, struts_action, u.s.

Guduri Venu Gopal : I am using Liferay sdk plugin-5.2.3 and the liferay version is also 5.2.3


I created a sample portlet with the help of lifeary sdk plugin.


Now I want to create some tabs in that portlet.


By default we are having view.jsp file.


I created 3 more files


sample_tab_1.jsp

sample_tab_2.jsp

sample_tab_3.jsp








and in the view.jsp I modified the code like this


--------------------------------------------------------








<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>





<portlet:defineObjects />








This is the <b>Sample JSP Portlet</b>. Use this as a quick way to include JSPs.








<%

String tabs1 = ParamUtil.getString(request, "tabs1", "Sample Tab 1");








PortletURL portletURL = renderResponse.createRenderURL();








portletURL.setWindowState(WindowState.NORMAL);//Here I am getting an error:WindowState.NORMAL cannot be resolved to a type.








portletURL.setParameter("struts_action", "/ext/reports/view_reports");

portletURL.setParameter("tabs1", tabs1);








String tabNames = "Sample Tab 1,Sample Tab 2,Sample Tab 3";



%>








<liferay-ui:tabs names="<%= tabNames %>" url="<%= portletURL.toString() %>" />








<c:if test='<%= tabs1.equals("Sample Tab 1") %>'>

<liferay-util:include page="sample_tab_1.jsp" >

</c:if>

<c:if test='<%= tabs1.equals("Sample Tab 2") %>'>

<liferay-util:include page="sample_tab_2.jsp" >

</c:if>

<c:if test='<%= tabs1.equals("Sample Tab 3") %>'>

<liferay-util:include page="sample_tab_3.jsp" >

</c:if>





---------------------------------------------------------








In the liferay UI it is showing" temperarily unavailable"

Can any one Plz help me in solving this...............






Mazhar Anwar : Add the following taglibrary and classes on top of your jsp.








<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>








<%@ page import="javax.portlet.PortletURL" %>

<%@ page import="javax.portlet.ResourceURL" %>

<%@ page import="javax.portlet.WindowState" %>








Regards,

Mazhar






Guduri Venu Gopal : Thanks Mazhar for ur reply..








I am having one small question





------------------------------------------








<%

String tabs1 = ParamUtil.getString(request, "tabs1", "Sample Tab 1");








PortletURL portletURL = renderResponse.createRenderURL();











portletURL.setWindowState(WindowState.NORMAL);

portletURL.setParameter("struts_action", "/ext/reports/view_reports");

portletURL.setParameter("tabs1", tabs1);








String tabNames = "Sample Tab 1,Sample Tab 2,Sample Tab 3";





%>

--------------------------------------------------





Here in





portletURL.setParameter("struts_action", "/ext/reports/view_reports");

I am not using any framework just simple jsp's in that case what are the parameters that i should pass in the place of ("struts_action", "/ext/reports/view_reports");








and any changes required in

portletURL.setParameter("tabs1", tabs1);






Guduri Venu Gopal : Thanks Mazhar for ur reply..





In the console I am an erroremoticonaramUtil cannot be resolved


Can u plz help me ..






Mazhar Anwar :


- No need to pass struts_action parameter since this is simple jsp portlet.








You can use liferay-ui:tabs in its simplest format as follows;
















- for tabs1: yes. if you are submitting any form or so.








There is a complete implementaion of Tabs in different ways in Liferay's enterprise admin portlet.








Regards,

Mazhar






Mazhar Anwar :


Added the following class in your jsp emoticon








<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>








Regards,

Mazhar






Guduri Venu Gopal : Hi Mazhar,





Finally I am able to display the tabs in the portlet but on click of the tabs nothing is displaying.








View.jsp

------------








<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<%@ page import="javax.portlet.PortletURL" %>

<%@ page import="javax.portlet.ResourceURL" %>

<%@ page import="javax.portlet.WindowState" %>

<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<%


String tabs1 = ParamUtil.getString(request, "tabs1", "Sample Tab 1");

PortletURL portletURL = renderResponse.createRenderURL();

portletURL.setWindowState(WindowState.NORMAL);

portletURL.setParameter("tabs1", tabs1);

String tabNames = "Sample Tab 1,Sample Tab 2,Sample Tab 3";

%>

<liferay-ui:tabs names="<%= tabNames %>" url="<%= portletURL.toString() %>" />



<c:if test='<%= tabs1.equals("Sample Tab 1") %>'>


<liferay-util:include page="/sample_tab_1.jsp" > //This jsp is created in parallel to view.jsp,is this the right way to access the jsp

</c:if>

<c:if test='<%= tabs1.equals("Sample Tab 2") %>'>

<liferay-util:include page="/sample_tab_2.jsp" >//This jsp is created in parallel to view.jsp,is this the right way to access the jsp



</c:if>

<c:if test='<%= tabs1.equals("Sample Tab 3") %>'>

<liferay-util:include page="/sample_tab_3.jsp" >//This jsp is created in parallel to view.jsp,is this the right way to access the jsp



</c:if>








sample_tab_1.jsp

----------------------------------------------------

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>



<portlet:defineObjects />








<H6>Tab1................</H6>



sample_tab_2.jsp

----------------------------------------------------

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>



<portlet:defineObjects />








<H6>Tab2................</H6>



sample_tab_3.jsp

----------------------------------------------------

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>



<portlet:defineObjects />








<H6>Tab3................</H6>






Attachments:






Abhed Dekavadiya : Hi Guduri Venu Gopal,








Did you get any luck on this?

I too need to create liferay tabs in a MVCPortlet.

Is it possible to do with MVCPortlet? or need to be done through struts-portlet only.

Please share your experience, reference of your working portlet.








Thanks in advance!

3 comments: