Kishore Sasidharan <kishore.sasidharan <at> cognizant.com> writes:
>
>
> Hi
>
> I want to provide a jsp popup in one of my portlets.I referred to the
> user chooser popup but it doesnot work for my application. Also the
> popup page has a html table that is populated from the database.Can
> anyone help me with this.
>
I looked at this posting because for some of my UI components, I will need to
employ pop-ups. So I took a look at the "user chooser" in the security
application. Note that using portlets complicates things when employing pop-ups
because the content displayed in the new window must still be in the context of
a portal page (although I present another possibility below).
I will try to break down how this mechanism works:
Let's say, we have a "source portlet" on which we want to display a link to
pop-up a "pop-up portlet".
1. Firstly, you must create a .psml page that will just display the pop-up
portlet so you don't get a whole portal page. In the case of the
"user chooser" for group management, take a look at:
<jetspeed webapp>/WEB-INF/pages/Administrative/choosers/multiusers.psml
It displays only the security::UserMultiChooser portlet (our pop-up portlet).
In a way this is somewhat unfortunate since your portlet application now relies
on a proprietary portal resource (the .psml page) present in another webapp
(the jetspeed webapp). Furthermore, your portlet application needs to know
the name of this foreign resource so that a URL to it can be constructed
(see #2). However, given the current state of the portlet specification, I
suppose you can't really complain.
2. So now you need to create a URL to this psml page. In the case of the
group details portlet, in it's doView method, it constructs the URL by calling:
SecurityUtil.getAbsoluteUrl(request,
"/Administrative/choosers/multiusers.psml");
This method of SecurityUtil then constructs an absolute URL like so:
public static String getAbsoluteUrl(RenderRequest renderRequest, String
relativePath)
{
RequestContext requestContext = (RequestContext)
renderRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
HttpServletRequest request = requestContext.getRequest();
StringBuffer path = new StringBuffer();
return requestContext.getResponse().encodeURL(
path.append(request.getScheme())
.append("://")
.append(request.getServerName())
.append(":")
.append(request.getServerPort())
.append(request.getContextPath())
.append(request.getServletPath())
.append(relativePath).toString()
);
}
3. The URL is saved in the request context and output on in the portlet's
display template (in this case
security/WEB-INF/security/groups/group-details.vm). A button to trigger the
pop-up is output...
<input onclick="javascript:openWindow('$userChooser')" type="submit"
name="group.action" value="Add Users to Group..."
class="portlet-form-button" />
...invoking the javascript...
function openWindow(pipeline)
{
var vWinUsers = window.open(pipeline, 'UserPicker',
'status=no,resizable=yes,width=200,height=300,scrollbars=yes');
vWinUsers.opener = self;
vWinUsers.focus();
}
4. And voila, clicking on the button opens a pop-up window with our pop-up
portlet.
Now in this particular case (and in mine as well), we select some items from
a form in the pop-up portlet in order to populate some data in our source
portlet.
At this point, the mechanics are the same as with any pop-up UI. You use
javascript on form submittal (of the pop-up portlet) to:
-capture the pop-up portlet form values and set some hidden field on the
parent window, in the correct source portlet form
-submit the source portlet form
-close the pop-up window.
Take a look at security/WEB-INF/security/users/user-multi-chooser.vm.
Note that no action is called in the pop-up portlet when the form is submitted,
although you could if you wanted if it were a multi-step process or whatever.
Another Approach:
A second approach would be to pop-up a URL to a servlet/JSP contained in your
portlet application directly (by-passing the portlet), rather than a psml page.
This has the advantage that you do not need to rely on a psml page in the
jetspeed application. However, it has the following disadvantages/challenges:
1. Your portlet application now deviates from a true portlet by calling
servlet resources outside of the portal.
2. You would need SSO enabled at the container level in all but the simplest
cases (you wouldn't if it was a publicly available portlet and you could
pass in whatever data params you needed in the URL).
This approach may seem like somewhat of a kludge and I am not saying it is
better by any means. However, it should be noted that this is *exactly* the
approach that is needed in order to trigger a download of a binary file from
a portlet.
Comments welcome. I hope this is useful to developers out there looking to
use pop-ups in their portlet UIs.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]