Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Nalin Asawa
changing display of portlet based on wider or narrow layout.
28 de Setembro de 2011 02:32
Resposta

Nalin Asawa

Ranking: New Member

Mensagens: 7

Data de entrada: 26 de Setembro de 2011

Mensagens recentes

Hi,

I have one portlet which should be displayed in different ways based on it's lay out position.
My page is in 2 column layout (70/30), left is wider and right one is narrow layout. if the portlet is dragged to wider, it should display me widerlayout contents( which I have defined in one jsp). and if it is dragged into the narrow column then it should display me a different layout (narrow jsp contents).

Please can any one tell me how to achieve this one.

Thanks and Regards,
Nalin.
Jelmer Kuperus
RE: changing display of portlet based on wider or narrow layout.
28 de Setembro de 2011 03:39
Resposta

Jelmer Kuperus

Ranking: Liferay Legend

Mensagens: 1192

Data de entrada: 10 de Março de 2010

Mensagens recentes

You could use this to determine which column you are in

1ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
2String columnId = themeDisplay.getPortletDisplay().getColumnId() ;


But keep in mind that what you are doing is pretty a-typical and also will not work with the ajax drag and drop stuff
Nalin Asawa
RE: changing display of portlet based on wider or narrow layout.
30 de Setembro de 2011 05:46
Resposta

Nalin Asawa

Ranking: New Member

Mensagens: 7

Data de entrada: 26 de Setembro de 2011

Mensagens recentes

Hi Liferay Master,

Thanks for your response.
using this I am getting In which column the portlet is placed. But i am not able to find the column is wider or narrow.
I have checked the ThemeDisplay but could not find a method for this.

I have to get this data when I move a portlet from one column to other column dynamically.
Is there any way to resolve this problem.

I need this as I need to change the UI based on the wider column or narrow column.

Thanks and Regards,
Nalin.
Jelmer Kuperus
RE: changing display of portlet based on wider or narrow layout.
30 de Setembro de 2011 08:46
Resposta

Jelmer Kuperus

Ranking: Liferay Legend

Mensagens: 1192

Data de entrada: 10 de Março de 2010

Mensagens recentes

Hi New member

It will only give you the name of the column. You yourself should map the column name to widths for every layout template. So for example if your page using a 30/70 layout then column1 will be 30 and column2 will be 70.
Nalin Asawa
RE: changing display of portlet based on wider or narrow layout.
20 de Outubro de 2011 00:12
Resposta

Nalin Asawa

Ranking: New Member

Mensagens: 7

Data de entrada: 26 de Setembro de 2011

Mensagens recentes

Hi,
Here my requirement is like I need to get the value of layout when we move the portlet from one column to other column.
when I move it... It's a ajax call I think... Its just placing it and on other layout. render method is not getting called here. so what ever I have written is not getting invoked.
String currentLayout = themeDisplay.getPortletDisplay().getColumnId();
if(null!=currentLayout && currentLayout.equalsIgnoreCase("column-2"))
{
return "wide";
}

so is there any event or method is called when we move from one layout to other layout. can we get an updated information when move portlet from one column to other column?
When I moved from one layout to other layout... on firebug->net tab, i could observe this action.
http://localhost:8080/c/portal/update_layout?cmd=move&doAsUserId=&p_l_id=10176&p_p_col_id=column-1&p_p_col_pos=0&p_p_id=applicationname_WAR_applicationname

Please I request you to let me know how to get the placed layout details on the move of portlet.

Thanks and Regards,
Nalin.
Nalin Asawa
RE: changing display of portlet based on wider or narrow layout.
30 de Outubro de 2011 23:51
Resposta

Nalin Asawa

Ranking: New Member

Mensagens: 7

Data de entrada: 26 de Setembro de 2011

Mensagens recentes

can anyone help me in resolving this problem.
Here can we use layout listener or some other listeners to get notified when the portlet moves from one layout to other layout?
Abdul Qadir
RE: changing display of portlet based on wider or narrow layout.
2 de Novembro de 2011 04:46
Resposta

Abdul Qadir

Ranking: New Member

Mensagens: 3

Data de entrada: 21 de Fevereiro de 2011

Mensagens recentes

While we drag portlet, liferay internally call functions from layout.js. So we have to hook liferay layout javascript.Like Spring Aop we can call method after, around for liferay javascript.
When we drag portlets on liferay portal, "saveIndex" method of layout.js is called. You have to hook this method with 'after' aspect. If you inspect saveIndex method, then there is findIndex method. you have to borrow some logic from here too. One more thing, dragging portlet has class "aui-dd-dragging" class during draggin event. So you have to paste this code on main.js of your theme to hooking liferay javascript for ajax request of your portlet.
----------------------------------Java Script method for main.js--------------------------
Liferay.on(
'allPortletsReady',
/*
This function gets loaded when everything, including the portlets, is on
the page.
*/

function() {
var A =AUI();
Liferay.Util.actsAsAspect(Liferay.Layout);
Liferay.Layout.after(
'saveIndex',
function () {
var userDrag = A.one('.aui-dd-dragging');
var columnNode = userDrag.get('parentNode');
var currentColumnId = Liferay.Util.getColumnId(columnNode.get('id'));
var customUrl = 'http://localhost:8080/web/guest/home?p_p_id=liferayInAction_WAR_liferayInActionportlet';
customUrl = customUrl+'&_liferayInAction_WAR_liferayInActionportlet_p_p_col_id='+currentColumnId;
alert('customUrl '+ customUrl);

AUI().use('aui-io-request, aui-node', function(A){

A.io.request(
customUrl , {
method : 'POST',
on: {

success: function() {
alert('success');
}
}
}
);
});
});
}
);
-----------------------End------------------------
I am not getting any other way for portletUrl right now so I have to hard code 'cuspomUrl'.

In your doView method of your portlet, you can easily get currentColumnId as

String columnId = ParamUtil.getString(renderRequest,"p_p_col_id","column-1");
and render your jsp according to columnId value.
Peter Mesotten
RE: changing display of portlet based on wider or narrow layout.
15 de Fevereiro de 2013 05:20
Resposta

Peter Mesotten

Ranking: Junior Member

Mensagens: 37

Data de entrada: 4 de Fevereiro de 2009

Mensagens recentes

Thanks a lot Abdul, this was a great help!