You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ricardo Jorge <rv...@gmail.com> on 2010/02/22 14:47:46 UTC

Custom Window State Struts2 Portlet

Hello.

I'm using Liferay portal to develop a portlet using struts 2. I need to use
a custom Liferay Window State called exclusive to generate a URL. This
allows me to make AJAX calls and return only the result generated by the
action. I have added the <custom-window-state> tag to my portlet.xml

I tried

<s:url windowState="exclusive" action="moreinformation">
          <s:param name="id" value="resourceId" />
</s:url>

but the windowState in the URL always ends up being 'normal' (I presume this
is the default). I did a quick look through the Struts2 code but I couldn't
find the place where this default value was processed (I will look in more
detail later).

I also tried

<portlet:actionURL windowState="exclusive">
          <portlet:param name="struts.portlet.action"
value="/gdocs/moreinformation" />
          <portlet:param name="id" value="---------------------" />
</portlet:actionURL>

and it works but I need to add a dynamic parameter (id) from the Value Stack
(I'm using s:iterator) but I have no idea how to put it there. <s:property>
doesn't work, using %{} or ${} doesn't work either.

Finally, I solved this problem the following way

<portlet:actionURL windowState="exclusive">
                  <portlet:param name="struts.portlet.action"
value="/gdocs/moreinformation" />
</portlet:actionURL>&amp;<portlet:namespace />id=<s:property
value="resourceId" />

but it feels kind of hackish and I think that there has to be a better way.

Any suggestions?

Best Regards,
Ricardo

Re: Custom Window State Struts2 Portlet

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
>From the source [1] (getWindowState method), it appears that only the
standard window states are considered when creating the url.

Please register a JIRA issue (tests and patch welcome indeed).

Regards,

Nils-Helge Garli Hegvik

[1] - http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java?view=markup

On Mon, Feb 22, 2010 at 2:47 PM, Ricardo Jorge <rv...@gmail.com> wrote:
> Hello.
>
> I'm using Liferay portal to develop a portlet using struts 2. I need to use
> a custom Liferay Window State called exclusive to generate a URL. This
> allows me to make AJAX calls and return only the result generated by the
> action. I have added the <custom-window-state> tag to my portlet.xml
>
> I tried
>
> <s:url windowState="exclusive" action="moreinformation">
>          <s:param name="id" value="resourceId" />
> </s:url>
>
> but the windowState in the URL always ends up being 'normal' (I presume this
> is the default). I did a quick look through the Struts2 code but I couldn't
> find the place where this default value was processed (I will look in more
> detail later).
>
> I also tried
>
> <portlet:actionURL windowState="exclusive">
>          <portlet:param name="struts.portlet.action"
> value="/gdocs/moreinformation" />
>          <portlet:param name="id" value="---------------------" />
> </portlet:actionURL>
>
> and it works but I need to add a dynamic parameter (id) from the Value Stack
> (I'm using s:iterator) but I have no idea how to put it there. <s:property>
> doesn't work, using %{} or ${} doesn't work either.
>
> Finally, I solved this problem the following way
>
> <portlet:actionURL windowState="exclusive">
>                  <portlet:param name="struts.portlet.action"
> value="/gdocs/moreinformation" />
> </portlet:actionURL>&amp;<portlet:namespace />id=<s:property
> value="resourceId" />
>
> but it feels kind of hackish and I think that there has to be a better way.
>
> Any suggestions?
>
> Best Regards,
> Ricardo
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Custom Window State Struts2 Portlet

Posted by Ricardo Jorge <rv...@gmail.com>.
I managed to fix it.

Although the hackish alternative I presented at the end of the message
worked, when I was implementing friendly URLs it didn't work as expected for
the id parameter because it wasn't a part of <portlet:actionURL>.

I found a way to get the ID from the value stack this way

ActionContext.getContext().getValueStack().findValue("resourceId").toString();

so my final code is now

<% String resourceId =
ActionContext.getContext().getValueStack().findValue("resourceId").toString();
%>
<portlet:actionURL windowState="exclusive">
          <portlet:param name="struts.portlet.action"
value="/gdocs/gdocs/moreinformation" />
          <portlet:param name="docid" value="<%= resourceId %>">
</portlet:param></portlet:actionURL>

and it's working perfectly well.

Best Regards,
Ricardo

On Mon, Feb 22, 2010 at 1:47 PM, Ricardo Jorge <rv...@gmail.com> wrote:

> Hello.
>
> I'm using Liferay portal to develop a portlet using struts 2. I need to use
> a custom Liferay Window State called exclusive to generate a URL. This
> allows me to make AJAX calls and return only the result generated by the
> action. I have added the <custom-window-state> tag to my portlet.xml
>
> I tried
>
> <s:url windowState="exclusive" action="moreinformation">
>           <s:param name="id" value="resourceId" />
> </s:url>
>
> but the windowState in the URL always ends up being 'normal' (I presume
> this is the default). I did a quick look through the Struts2 code but I
> couldn't find the place where this default value was processed (I will look
> in more detail later).
>
> I also tried
>
> <portlet:actionURL windowState="exclusive">
>           <portlet:param name="struts.portlet.action"
> value="/gdocs/moreinformation" />
>           <portlet:param name="id" value="---------------------" />
> </portlet:actionURL>
>
> and it works but I need to add a dynamic parameter (id) from the Value
> Stack (I'm using s:iterator) but I have no idea how to put it there.
> <s:property> doesn't work, using %{} or ${} doesn't work either.
>
> Finally, I solved this problem the following way
>
> <portlet:actionURL windowState="exclusive">
>                   <portlet:param name="struts.portlet.action"
> value="/gdocs/moreinformation" />
> </portlet:actionURL>&amp;<portlet:namespace />id=<s:property
> value="resourceId" />
>
> but it feels kind of hackish and I think that there has to be a better way.
>
> Any suggestions?
>
> Best Regards,
> Ricardo
>