Suppose portlet X is deployed to Liferay and has a friendly URL mapped. Suppose a user enters the Liferay Portal via a the mapped URL but the portlet is not present in the portal - it's deployed but not added to the page.
My problem is that when the user uses the mapped URL nothing happens - the portal gives no visual feedback, that the target portlet is not present.
How can I change that? I need some kind of an alert / notice to the user...
-- edit --
I need not use a second portlet to check the presence of yet another portlet.
Kindest regards,
AFAIK, there is no natual way to make that happen. A portlet need not always be installed on a page. So, the behaviour is quite normal.
One rather hacky solution I could think of:
Get hold of the ThemeDisplay object in a JSP using <liferay-theme:defineObjects /> which would expose the implicit object themeDisplay in the JSP scope.
Get hold of the type settings string using:
String typeSettings = themeDisplay.getLayout().getTypeSettings();
Type settings will have values like the below:
layout-template-id=foobar_2column
sitemap-include=1
column-1=foo_WAR_barportlet,abc_WAR_barportlet,56_INSTANCE_K4Vv,
column-2=baz_WAR_xyzportlet,
sitemap-changefreq=daily
So if you have a non-instanceable portlet with ID foo inside WAR
file bar, the portlet's unique ID on the layout will be
foo_WAR_barportlet.
Once you know the portlet ID that you're expecting to be present,
it's just a matter of string contains check.
<% if(!typeSettings.contains("foo_WAR_barportlet")) { %>
<h3 style="color: red">Alert! Portlet foo_WAR_barportlet not installed.</h3>
<% } %>
You can do the above steps even inside a theme, but you'll have to do it in Velocity instead of Java then. Hope that helps.
EDIT
You can add this line inside your portal_normal.vm
#if(!$layout.getTypeSettings().contains("foo_WAR_barportlet"))
<h3 style="color: red">Alert! Portlet foo_WAR_barportlet not installed.</h3>
#end
Yes you can achieve that using Inter-portlet communication, for notifying the user whether the portlet is added to the page or not. you need to create another portlet(lets call it ListenerPortlet) which by default sits on the page.
you can add the Listener portlet to the theme, so that it is by default added to every page.
Now, when you add your portlet to your page, your portlet should trigger a client-side javascript event and notify your Listener portlet that your portlet is added to your page.
From your portlet call,
Liferay.trigger(eventName, data)
and bind your Listener portlet to the event
Liferay.bind(eventName, function, [scope]) //make the scope as page
This way your Listener portlet will know if your portlet is added to the page or not. and you can display a message to the user if the portlet is not added.
For further reference check the IPC
and more specifically client-side Inter portlet communicaton
It would be better if we try this,
ThemeDisplay themeDisplay = request.getAttribute(WebKeys.THEME_DISPLAY);
Layout layout = LayoutLocalServiceUtil.getLayout(themeDisplay.getLayout().getPlid());
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
List allPortletIds = layoutTypePortlet.getPortletIds();
If the list is empty then the page doesnt contain any portlets.
Gettings the LayoutTypePortlet ensures that page the user has been redirected to is layout type portlet.
Related
I 'm learning to write a portlet in liferay portal 6.1 and I use spring mvc portlet, I have an issue when I redirect page 1 to page 2 by using action phase in portlet.
And I will display some infomation by the id which have been passed when i redirect page 1 to page 2
So are there any ways to display an image from a portlet of page 1 to an other portlet in page 2 ?
Thanks in advance.
There is no way you can access the information passed from Portlet 1 in Portlet 2 using ActionRequest or RenderRequest, whichever possible.
First you need to get the original HttpServletRequest Object using PortalUtil class and then get the required parameters using ParamUtil, if possible.
The parameters which are passed through page redirection doesn't fall under any PortletRequest. Hence, they cannot be accessed directly using Action or Render request Object.
I am using java liferay portal, in which there are multiple portlets. I want to create a portlet with a form that when it is submitted the data is retrieved and the specific result is shown in some other page portlet. But unfortunately these things are not going in the way.
I was thinking of using sessions but 2 problems arrised.
javascript value assignment to java variable.
if the values are passed to the page on which the specific portlet is placed, that portlet doesn't get the values.
Then I heard the concept of Inter Portlet Communication(IPC), and took some help from "liferay in action" but there the code works if both the portlets are placed on the same page, and my requirement is that one portlet is placed on first page and when the form is submitted it is redirected to the second page, to the second portlet for getting the parameters. I tried more example but its not working in my way.
I have found another way of, a relatively easiest, just tried that wiki from liferay
As i understood, you have some JavaScript parameters which you want to pass to the next page. You can, though, do it with APPLICATION_SCOPE of PortletSession and you can solve the problem of converting JS params to Java by placing the values in a input. If these input vars aren't supposed to be written by the user and you take them from somewhere else, you can make the input hidden:
In your jsp:
<form>
<input type="hidden" id="myinput1" name="in1" value="">
<input type="hidden" id="myinput1" name="in2" value="">
</form>
<script>
var a = "avalue";
var b = "bvalue";
document.getElementById("myinput1").value=a;
document.getElementById("myinput2").value=b;
</script>
Then submit the form when you need to. Next, you'll be able to do like this in the ProcessAction method of the portlet:
String a= request.getParameter("in1");
String b= request.getParameter("in2");
PortletSession session = request.getPortletSession();
session.setAttribute("a", a , PortletSession.APPLICATION_SCOPE);
session.setAttribute("b", b , PortletSession.APPLICATION_SCOPE);
In the other portlet, you can find it by calling
session.getAttribute("a",PortletSession.APPLICATION_SCOPE);
This, of course, if you can't simply place them in the next page's url.
As far as I know IPC does indeed only work between portlets on the same page. Also the portlet specification doesn't provide a generalized mechanism for switching pages so you can only use portal vendor specific ways to achieve that. But using public render parameters and a correctly constructed Liferay URL to another page you should be able to achieve the result you want: http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1207858
In the base template for the pages of my Wicket application, there's a form I don't want Wicket to handle, like this:
<form id="myForm" action="">
<!-- input fields and submit button -->
</form>
I left the action attribute empty to always send it to the current page. On the application's main page, it works, but on other pages, Wicket adds a "../" in the action attribute, which seems to be meant well but is not what I want.
I'm using Wicket 1.4.17. How can I stop or change this behaviour?
The form is meant to enable the user to submit a short message as feedback to the site admin. It appears on every page and the input is collected from the PageParameters in the constructor of my pages' base class. If there is a more Wicket way to do this, I'll appreciate hints, but this should be a) stateless and b) very very simple.
I'd go the Wicket way and write a component for your feedback form which is then inserted into every page. As you have an (abstract) base class for all of your pages, you can simply add it there and it will appear on every page.
In your feedback form component, simply overwrite the onSubmit() method and send the message to the site admin.
I have a JSF page that loads a User and allows me to assign Roles to that particular User. The Backing Bean, AssignRolesBean is #RequestScoped, and I would like for it to remain so. However, here's my problem...
When the form submits, it calls AssignRolesBean.execute(). This then returns the path to the confirmation page. On this confirmation page, I want to show what new roles will be assigned and which role will be removed. However, I'm having trouble getting the User loaded on the confirmation page.
On the initial AssignRoles page, the userId is set using a GET parameter. It is then added as an h:inputHidden element on the page. It does get submitted. But, again, on the next page, the userId is not set (which loads the User). Is there any way I can keep the RequestScope and not have to store the userId in the SessionMap? I've been told that using hidden inputs will allow you to take data across pages. But, I'm having trouble with that.
if you develop jsf2 app, you can use flash scope to pass the parameters.
For more information about flash scope you can look at Learning JSF2: Using Flash scope
or you can put the parameters into session map
code snippet to get sessionMap:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
Add the following to your view to execute an action upon a GET request:
<f:metadata>
<f:event type="preRenderView" listener="#{bean.init}" />
</f:metadata>
with
public void init() {
// Request parameters which are set by h:inputHidden, #ManagedProperty
// or f:viewParam are available here.
// You can just do e.g:
this.user = userService.find(userId);
}
I've set up a Liferay community, along with a number of pages each defining there own set of portlets, themes and layouts. I want to be able to create links between these pages. For example given that I am at the top level page (lets call this 'home'), I want to link to another page (for example 'blog') from within one of my portlets.
Is there a way, either using the Liferay or Portlet APIs to create a render url based on a page parameter that I supply. As far as I can see, the liferay-portlet-ext taglib defines a renderUrl tag that I can use to create a URL that links back to the same page, however I can't see a way to specify the page name in this tag.
I'm using Liferay 5.2.3. Thanks in advance.
You can either link them with friendlyURLs (/web/othergroup/blog) or you can use
PortletURL portletURL = PortletURLFactoryUtil.create(
request, portletName, plid, lifecycle);