Message Boards

Remember Current Tab <liferay-ui:tabs>

thumbnail
Pascal Wasem, modified 15 Years ago.

Remember Current Tab <liferay-ui:tabs>

New Member Posts: 17 Join Date: 3/31/10 Recent Posts
Hi!

I have some tabs in my jsp-file!
Like this:

<liferay-ui:tabs names="Search,Browse" refresh="<%= false %>">
    <liferay-ui:section>
             <form id="<portlet:namespace/>SearchForm" action="<portlet:actionURL   
                  name=" SearchProcess">" method="POST"&gt;
                  <input id="<portlet:namespace/>Input" type="text" name="Input">
            </form>
    </liferay-ui:section>
    <liferay-ui:section>
      <a href="
               <portlet:actionURL name=" selectprocess">
                    <portlet:param name="process" value="<%= someValue %>" />
               "
      &gt; &lt;%= someValue %&gt; </a>
    </liferay-ui:section>
</liferay-ui:tabs>


As you can see the first tab contains a form with an input box
the second one a link!
Both create an actionUrl!

The Problem:
If I click the link in the second tab (->actionUrl), the second tab becomes unselected!

How to remember which tab was selected before the request?

By the way there ANY (detailed) documentation about how to use the liferay taglibs?

Thank you!

Best regards,
Pascal
Mazhar Anwar, modified 15 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

Regular Member Posts: 125 Join Date: 2/5/10 Recent Posts
You can get last selected tab in you jsp from request parameter as follows,

<% String tabs1 = ParamUtil.getString(request, "tabs1", "Search");%>

And You need to create instance of PortletURL,

PortletURL portletURL = renderResponse.createRenderURL();
portletURL.setWindowState(WindowState.MAXIMIZED);
portletURL.setParameter("tabs1", tabs1);

AND

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

OR

<portlet:actionURL name="SelectProcess">
<portlet:param name="process" value="<%= someValue %>"/>
<portlet:param name="tabs1" value="<%=tabs1 %>" />;
</portlet:actionURL>"

For more details about Tabs taglibs you can explore the enterprise admin porlet in portal source. You will find it in portal/portal-web/docroot/html/portlet/enterprise_admin.

HTH...

Regards,
Mazhar
thumbnail
Pascal Wasem, modified 15 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 17 Join Date: 3/31/10 Recent Posts
Hi Mazhar,

Thank you for your response!
But this only helped me partially.
Althoug I think I am on the right way.


I'am using this now in my jsp:


&lt;%
PortletURL portletURL = renderResponse.createRenderURL();
String tabs1 = ParamUtil.getString(request, "tabs1", "Search");
portletURL.setParameter("tabs1", tabs1);
%&gt;
...
<liferay-ui:tabs names="Search,Browse" refresh="<%= false %>">
...
</liferay-ui:tabs>


The problem is that even if I forward the tabs1-param in the action url it ALWAYS remains "Search".
It seems like the current selected tab is not stored in tabs1?

Although setting it to "Browse" in my Portlet-Class works fine!

@ProcessAction(name = "ShowAll")
public void handleShowAllAction(ActionRequest request, ActionResponse response)
{
        String tabs1 = request.getParameter("tabs1"); //value is always "Search"
        logger.info("tabs1 = " + tabs1);
        response.setRenderParameter("tabs1", "Browse"); //this works!
}


What am I missing!
Has it sth to do with param, url or refresh in <liferay-ui:tabs> ?

Thanks!

Best,
Pascal
thumbnail
Sandeep Nair, modified 15 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

Liferay Legend Posts: 1744 Join Date: 11/6/08 Recent Posts
Hi,

Use this along with the above changes

<liferay-ui:tabs names="Search,Browse" param="tabs1" refresh="<%= false %>">

And in both the action pass the following parameter

<portlet:param name="tabs1" value="Search" /> in the first

and <portlet:param name="tabs1" value="Browse" /> in second

Regards
Sandeep
thumbnail
Pascal Wasem, modified 15 Years ago.

RE: Remember Current Tab <liferay-ui:tabs> (Answer)

New Member Posts: 17 Join Date: 3/31/10 Recent Posts
Thanks Sandeep, that did it!
Gourab Kar, modified 15 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 6 Join Date: 5/11/10 Recent Posts
ok everybody out there... hi and greetings.

At last I solved the problem. I had to get inside liferay-UI:tabs tld's init jsp.

what we all did was
<liferay-ui:tabs
names="tabs1, tabs2" //"Skills,Notification" in my case
param="tab"
url="<someURL>"
/>

but we are missing a very highly critical info in tabs tag- that is 'value' or 'values'.
the param passes the tab string that we get as a string along with default value, but the value attribute is the main variable that defines the desired tab.

if we don't pass anything as value, then for every inner rendering/ request will make the default tab active.

so try this:
<liferay-ui:tabs
names="tabs1, tabs2" //"Skills,Notification" in my case
param="tab"
url="<someURL>"
value="tab1" //this will always keep tab1 active
/>

and this one:
<liferay-ui:tabs
names="tabs1, tabs2" //"Skills,Notification" in my case
param="tab"
url="<someURL>"
value="tab2" //this will always keep tabs2 active
/>


and finally this one:
<liferay-ui:tabs
names="tabs1, tabs2" //"Skills,Notification" in my case
param="tab"
url="<someURL>"
value="<%=currentTab%>"
/> //this will always keep the current value you are getting on tab

My sincere thanks to sandeep nair who worked with me on this and my senior Tarun who guided me.
Anders Olme, modified 14 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 6 Join Date: 6/11/10 Recent Posts
How do you set the

<liferay-ui:tabs
names="tabs1, tabs2" //"Skills,Notification" in my case
param="tab"
url="<someURL>"
value="<%=currentTab%>"
/>

currentTab variable to to the correct value (or is it some kind of liferay system variable)?

Brg Anders Olme
Gourab Kar, modified 14 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 6 Join Date: 5/11/10 Recent Posts
Yes values is a liferay's system parameter(variable) and <%=currentTab%> is the jsp scriptlet.
So for the first time when this portlet is loaded currentTab at the beginning will be null so the param will pass the initial value.

For every next iteration the currentTab will be what is set from the respective jsps as setAttribute

Eg: request.setAttribute("tab", <value of the tab that you want to pass>)

And this is received in another jsp, especially the init jsp as
currentTab = getAttribute("tab");

<liferay-ui:tabs value=<%currentTab%>...>
Anders Olme, modified 14 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 6 Join Date: 6/11/10 Recent Posts
Oki, thanks for the answer!

BRG Anders Olme
Ratan Swami, modified 13 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 11 Join Date: 9/15/11 Recent Posts
We can also set the value of current tab in action/render URL using setParameter as :

PortletURL renderURL = renderResponse.createRenderURL();
renderURL.setParameter("tab1","<Name of your current Tab>");

and then retrieve the value in the file controlling file (view.jsp).
Nasir Hussain, modified 9 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

New Member Posts: 18 Join Date: 4/26/10 Recent Posts
I got into the same problems, for convenience i am providing all the info required use case for 3 tabs with search container in Liferay 6.2

This is the main jsp

&lt;%@page import="javax.portlet.PortletURL"%&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;

&lt;%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %&gt;&lt;%@
taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %&gt;&lt;%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %&gt;&lt;%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %&gt;&lt;%@
taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %&gt;

<portlet:defineobjects />

<liferay-ui:tabs names="This is tab1,This is tab2,This is tab3" param="tab" refresh="false" tabsvalues="This is tab1,This is tab2,This is tab3">
    <liferay-ui:section>
    	&lt;%@ include file="tab1.jspf"%&gt;      
    </liferay-ui:section>
    <liferay-ui:section>
        &lt;%@ include file="tab2.jspf"%&gt;
    </liferay-ui:section>
    <liferay-ui:section>
         &lt;%@ include file="tab3.jspf"%&gt;
    </liferay-ui:section>
</liferay-ui:tabs>


Here is tab1.jspf, also tab2.jspf and tab3.jspf will be similar


&lt;%
   	PortletURL portletURL = renderResponse.createRenderURL();
   	portletURL.setParameter("tab", "This is tab1");
%&gt;
<aui:fieldset label="Welcome to tab1">
	<liferay-ui:search-container delta="10" total="<%=list.size()%>" deltaconfigurable="false" iteratorurl="<%= portletURL %>" curparam="tab1param">
		<liferay-ui:search-container-results results="<%=ListUtil.subList(list, searchContainer.getStart(), searchContainer.getEnd())%>" />
		<liferay-ui:search-container-row .... ..... < liferay-ui:search-container-row>
		<liferay-ui:search-iterator />
	</liferay-ui:search-container-row></liferay-ui:search-container>
</aui:fieldset>


So when clicking on results in a particular tab, remember to add the parameter in the url that is mentioned in liferay-ui:tabs (i.e for this example is param="tab")
yang wang, modified 8 Years ago.

RE: Remember Current Tab <liferay-ui:tabs>

Junior Member Posts: 80 Join Date: 8/24/15 Recent Posts
With refresh = false, the below code works well for me.
&lt;%@page import="javax.portlet.PortletURL"%&gt;
&lt;%@ page contentType="text/html; charset=UTF-8"%&gt;
&lt;%@ include file="/common/init.jsp"%&gt;
&lt;%
        String curTab = ParamUtil.getString(request, "curTab" , "a");  //set the default tab
	request.setAttribute("curTab", curTab);
%&gt;
	
<liferay-ui:header title="test tabs" backURL="" />
<liferay-ui:tabs names="a,b,c,d" type="pills" refresh="false" value="${curTab }">
	<liferay-ui:section>
		a
	</liferay-ui:section>
	<liferay-ui:section>
		b
	</liferay-ui:section>
	<liferay-ui:section>
		c
	</liferay-ui:section>
	<liferay-ui:section>
		d
	</liferay-ui:section>
</liferay-ui:tabs>

The value attribute indicates the current active tab.