Fórum

How to Know where my portlet been dropped ???

suman alapati kumar, modificado 12 Anos atrás.

How to Know where my portlet been dropped ???

New Member Postagens: 17 Data de Entrada: 06/03/09 Postagens Recentes
Hi All,

I have a requirement where i want to know my portlet is dropped i mean which page by programatically ,
As i know by seeing previous blogs we can come to know by page name and friedly URL of my portlet by using ThemeDisplay API ,
but in my case i can't validate my code against page name or friendly URL the reason is my Admin may change the page name or friendly URL as per my business client(I am using single piece of Portlet across All my Clients).

Example :

Let say i have 3 pages called PageA , PageB , PageC and /pagea ,/pageb, /pagec are my respective friendly URL's , my requirement is when i click on any one of the page my portlet(I Dropped same portlet in all my Pages) should display the page name WITHOUT COMPARING PAGE NAME OR FRIENDLY-URL..


Thanks in Advance emoticon,
Suman Alapati.
Roshan Qureshi, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

Regular Member Postagens: 159 Data de Entrada: 24/08/10 Postagens Recentes
suman alapati kumar:
Hi All,

I have a requirement where i want to know my portlet is dropped i mean which page by programatically ,
As i know by seeing previous blogs we can come to know by page name and friedly URL of my portlet by using ThemeDisplay API ,
but in my case i can't validate my code against page name or friendly URL the reason is my Admin may change the page name or friendly URL as per my business client(I am using single piece of Portlet across All my Clients).

Example :

Let say i have 3 pages called PageA , PageB , PageC and /pagea ,/pageb, /pagec are my respective friendly URL's , my requirement is when i click on any one of the page my portlet(I Dropped same portlet in all my Pages) should display the page name WITHOUT COMPARING PAGE NAME OR FRIENDLY-URL..


Thanks in Advance emoticon,
Suman Alapati.


Hi Suman,

You can get friendly url from theme and then can use it to get the page name.
String friendlyUrl=themedisplay.getLayout().getFriendlyURL()
Then you can use
Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
themeDisplay.getScopeGroup().getGroupId(),
false,
friendlyUrl);
layout.getName() will give you the layout name

Let me know if still having query.
suman alapati kumar, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

New Member Postagens: 17 Data de Entrada: 06/03/09 Postagens Recentes
Hi Roshan,

Thanks for the Updates , but i don't want to compare my portlet code against the friendly-url or page Name , since in my case there is a chance , my liferay admin guy to give his own page name or friendly-URL.

Scenario :

Suppose instead of PageA if he created as PageAA or respective friendly-URL instead of /pagea if he gives /pageaa
then "themedisplay.getLayout().getFriendlyURL()" or "themeDisplay.getLayout().getName(themeDisplay.getLocale());" code which you have suggested is not going to work no logger.

I am expecting some thing like is there anyway that i can compare my portal code with page ID or some other ID's rather then pageName or Friendly-URL.

Thanks In Advance,
Suman Alapati.
Roshan Qureshi, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

Regular Member Postagens: 159 Data de Entrada: 24/08/10 Postagens Recentes
Hi Suman,

I have not checked it but I think the following code will work always even if admin changes any or both of pageName/friendly url.
Here we are getting friendly url from theme which will be always the latest one. So once the admin has changed it, we will get the new one now and the new page name against that friendly url.

String friendlyUrl=themedisplay.getLayout().getFriendlyURL()
Then you can use
Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
themeDisplay.getScopeGroup().getGroupId(),
false,
friendlyUrl);
layout.getName() will give you the layout name

Let me know if any query. I hope this will work for you.
suman alapati kumar, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

New Member Postagens: 17 Data de Entrada: 06/03/09 Postagens Recentes
Hi Roshan,

Thanks for the updates , As i agree with You that we can get page name as well as friendly URL as per recent updates . But that statements can not resolve my problem , let me give the better picture , Here is my Piece of my portlet code :

public class calculatorPortlet extends GenericPortlet {
public void doView(
RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {

String portlet="";

//The above String is empty since i don't know what has to be use . But surly neither page name nor friendlyURL The reason behind this can get information from below Simulation Steps:

if(portlet.equalsIgnoreCase("Add"))
{
System.out.println(2+3);
}
else if(portlet.equalsIgnoreCase("Subtract"))
{
System.out.println(2-3);
}
else if(portlet.equalsIgnoreCase("Multiplication"))
{
System.out.println(2*3);
}
else if(portlet.equalsIgnoreCase("Division"))
{
System.out.println(2/3);
}


include(viewJSP, renderRequest, renderResponse);
}

}

Simulation Steps:

This is my CalculatorPortlet which can do Add,Sub,Mul,Div

1-I have Created Add , Sub , Mul , Div Pages with /add , /sub , /mul , /div as friendly URL's
2-I have been dropped this Portlet in all the above pages
3-Then I hand over this code along with my exported .lar file to my admin to be deployed in other box(Another server lets say)
4-Admin has imported .lar file along with code
5-Admin has changed the page of Add to Addition and FriendlyURL /add to /addition (lets say) due to some reasons
6-After these changes he been accessed this portlet from Addition Page where the problem comes into Picture since pagename Called Add no longerExists


Finaly i mean to say is , if my code is tightly coupled with pagename or friendlyurl , i can't change the pagename or friendlyURL in feature . Hence i want to compare
with Some pageID or some other ID's kind of stuff . So that my code should will work even Pagename or FriendlyURL got changed in feature

Is there any Way that liferay supprorts to accept user Defined ID against each page while creation so that in my code i can compare with that ID , Hence i no need to Worry about what page names or FriendlyURL's has given my Admin


Thanks in Advance,
Suman Alapati.
Roshan Qureshi, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

Regular Member Postagens: 159 Data de Entrada: 24/08/10 Postagens Recentes
It means you want to perform four operations using one portlet and for each operation you will have a page and same portlet is there on all pages.
And for some page you want it to work for addition for another page you want it to work for sub and so on.
You can use portlet preferences and provide one field like action as a combo-box having all actions - add, sub, mul, div
Then fetch it from preferences in your process action and check it and process in the same way as you are doing.
In this case your same portlet will work for different operation for each page as defined in portlet configuration.

Hope this will help you.
suman alapati kumar, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

New Member Postagens: 17 Data de Entrada: 06/03/09 Postagens Recentes
Hi Roshan,

Thanks again for you updates emoticon , But I don't want to capture any extra field , which say's what my Portlet Actually Does .Since the end User is Accessing my Portlet from Specific Menu name and he wants to do . And there is no meaning to ask my end user again to capture What he wants.

And I don't want use Portlet Preferences , Since these Preferences will be exists until Portlet exists in the page if my portlet is unfortunately removed then these preferences has to reconfigure again.

Is there any alternative way to resolve my problem.

Thanks In Advance,
Suman Alapati. emoticon
Roshan Qureshi, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

Regular Member Postagens: 159 Data de Entrada: 24/08/10 Postagens Recentes
Hi Suman,

For this to work you should have atleast one thing (parameter/variable or any other) which is not going to change even the page-name or url is changing.
I also want to focus on one thing that page creation, portlet dropping and configurations are done by Admin and end user is not changing configurations generally (May be not right in your case) and if so you can use portlet configuration.
SEcond solution is to use query string while creating the page and keeping them always same. For example, you can use action=add for the page add
and action=sub for page substraction and so on and then you can fetch it in your portlet and can process accordingly.
suman alapati kumar, modificado 12 Anos atrás.

RE: How to Know where my portlet been dropped ???

New Member Postagens: 17 Data de Entrada: 06/03/09 Postagens Recentes
Hi Roshan,

Thanks for Your updates , relay impressed for your alternate methods for the ans finally i found one way to fix my issue as of now .

As we know while creating page there is any option to give description : I been used that attribute to find my portlet placement even though there is a chance to my Admin to change even that attribute in my case chances of changing that attribute by admin is less so i processed that method for finding my portlet.

In case if you find some other alternative please let me know :-)

Any Ways thanks for Your Coordination,

Suman Alapati.