migueloop
migueloop

Reputation: 541

liferay-ui:tabs not changing active

I'm having troubles with liferay-ui:tabs

I need to set an active tab depending on what link was previously clicked. I get this information though an String

String selectedTab = ParamUtil.getString(request, "valA", "generalSettings");

Then I create the tabs:

<liferay-ui:tabs
names="A,B,C,D,E"
tabsValues="valA,valB,valC,valD,valE" refresh="false"
value="<%=selectedTab%>" url="<%=tabURL.toString()%>" param="tab">
<liferay-ui:section>
    <%@ include file="a.jsp"%>
</liferay-ui:section>
<liferay-ui:section>
    <%@ include file="b.jsp"%>
</liferay-ui:section>
<liferay-ui:section>
    <%@ include file="c.jsp"%>
</liferay-ui:section>
<liferay-ui:section>
    <%@ include file="d.jsp"%>
</liferay-ui:section>
<liferay-ui:section>
    <%@ include file="c.jsp"%>
</liferay-ui:section>

The problem is that if use value parameter I this tab remains actived all the time although when I click other tabs I see the other imports.

Any idea?

Upvotes: 0

Views: 1772

Answers (2)

migueloop
migueloop

Reputation: 541

I have found the answer by creating a RenderURL and to bind it to the url parameter. The only problem that I have now is that every time I change names and tabValues if they are distinct it doesn't show the section content.

Upvotes: 0

Pawel Kruszewski
Pawel Kruszewski

Reputation: 569

I'll try to give you some hints here. I think you have a two typos.

  1. Your parameter is called tab, not selectedTab (as defined in param attribute),
  2. your allowed tab values (defined in tabsValues attribute) are: valA, valB etc.; generalSettings is not there.

Try this line:

String selectedTab = ParamUtil.getString(request, "tab", "valA");

If you just want the first tab to be selected it should be enough to remove value attribute of <liferay-ui:tabs> altogether. Check tabs implementation- when value is null it'll read parameter tab from request itself and select first tab by default when no value is provided.

With refresh set to false however you shouldn't get no page refresh that means selectedTab will not be initialized with every click on the tab. That's because all sections are pre-rendered on the page and only Liferay.Portal.Tabs.show is called to show the clicked one and hide the others.

Upvotes: 1

Related Questions