Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Neha Dhingra
How to pass request to JSP page using <portlet:renderURL > tag
January 15, 2009 4:54 AM
Answer

Neha Dhingra

Rank: New Member

Posts: 5

Join Date: January 1, 2009

Recent Posts

Hi,

How can we pass control to a JSP page instead of Action class using <portlet:renderURL > tag in liferay.Pls help.

Thanks
Tobias Gindler
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 15, 2009 1:49 PM
Answer

Tobias Gindler

Rank: Junior Member

Posts: 71

Join Date: March 23, 2007

Recent Posts

Hi,

In liferay 5.1.2 the renderURL and the param tags are defined inside the liferay-portlet.tld. They have the following definition:
 1<tag>
 2   <name>renderURL</name>
 3   <tag-class>com.liferay.taglib.portlet.RenderURLTag</tag-class>
 4   <tei-class>com.liferay.taglib.portlet.RenderURLTei</tei-class>
 5   <body-content>JSP</body-content>
 6   <attribute>
 7       <name>windowState</name> <!-- may be : maximized | normal | minimized-->
 8       <required>false</required>
 9       <rtexprvalue>true</rtexprvalue>
10   </attribute>
11   <attribute>
12       <name>portletMode</name> <!-- may be : view | edit | help -->
13       <required>false</required>
14       <rtexprvalue>true</rtexprvalue>
15   </attribute>
16   <attribute>
17       <name>var</name>
18       <required>false</required>
19       <rtexprvalue>true</rtexprvalue>
20   </attribute>
21   <attribute>
22       <name>secure</name>
23       <required>false</required>
24       <rtexprvalue>true</rtexprvalue>
25   </attribute>
26   <attribute>
27       <name>copyCurrentRenderParameters</name>
28       <required>false</required>
29       <rtexprvalue>true</rtexprvalue>
30   </attribute>
31   <attribute>
32       <name>escapeXml</name>
33       <required>false</required>
34       <rtexprvalue>true</rtexprvalue>
35   </attribute>
36</tag>
37
38<tag>
39   <name>param</name>
40   <tag-class>com.liferay.taglib.util.ParamTag</tag-class>
41   <body-content>JSP</body-content>
42   <attribute>
43       <name>name</name>
44       <required>true</required>
45       <rtexprvalue>true</rtexprvalue>
46   </attribute>
47   <attribute>
48       <name>value</name>
49       <required>true</required>
50       <rtexprvalue>true</rtexprvalue>
51   </attribute>
52</tag>


So you have to do the following to use the renderURL tag:
1<portlet:renderURL var="varName">
2    <portlet:param name="paramname" value="param value" />
3</portlet:renderURL>
4
5<!-- How to use -->
6<a href="<%=  varName %>" >some link</a>
7<!-- or -->
8<a href="${varName}">some link</a>


That will force the page to render and passes some parameters to a specific portlet.

Best regards
Tobias
Neha Dhingra
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 15, 2009 9:36 PM
Answer

Neha Dhingra

Rank: New Member

Posts: 5

Join Date: January 1, 2009

Recent Posts

Hey..thanks for such a good explanition...but i guess i had put question in wrong way..
The question is that the way i can pass request to an action class using paramter "struts_action", wherein i give the path of action class in the value attribute..How can i move to a JSP page instead of Action class using renderURl.

Thanks,
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 28, 2009 1:03 PM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Hi Gindler,

How to use <portlet:renderURL> to invoke an action through href? I want to render the result JSP page in a Pop-up window with no portal theme at all. I have been suggest to use <portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>" ...>. I could not understand how to use this and where to use it.

Could you please help in explaining how to use <portlet:renderURL> for a pop-up window with no portal theme being used?
Victor Zorin
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 28, 2009 1:46 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

I want to render the result JSP page in a Pop-up window ...

see code below
 1
 2<a
 3   href="<portlet:renderURL
 4          windowState="<%=LiferayWindowState.EXCLUSIVE.toString() %>"
 5          <portlet:param
 6              name="_spage"
 7              value="/portlet_action/your_render_path"/>
 8       </portlet:renderURL>"
 9   target="new_window_name">
10view portlet in a popup without theme
11</a>

The above code will display portlet in a seperate browser window.
If you need an AJAX popup, use Liferay.Popup(options) method.
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 29, 2009 12:59 PM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Thanks, Victor

I tried ur solution but could NOT get it working. I tried to invoke a struts action class but the pop-up window showed just the tiles template i am using in the struts app.
I checked the URL and it had the action i wanted to invoke. But i was NOT invoking the action and rendering the result in the pop-up except the template.
In my tomcat log file I could see this ERROR:

23:47:55,453 ERROR [UploadServletRequestImpl:111] the request doesn't contain a multipart/form-data
type header is application/x-www-form-urlencoded
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
January 29, 2009 12:59 PM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Hi Victor,

I have an another query in regard to this. How can I use this <html:form action="/myportlet/myaction" method="post"> to achieve the same result i.e. the mapping.findforward in my action class shows the result in a JSP page and this should be shown in pop-up window with no theme. Could you please help me with this as well?
Victor Zorin
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 3, 2009 7:40 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

23:47:55,453 ERROR [UploadServletRequestImpl:111] the request doesn't contain a multipart/form-data
type header is application/x-www-form-urlencoded
- it seems that this error has nothing to do with our code, liferay5.1.2 has started producing it without any reason.

Below is an extract from our view.jsp that uses Popup feature:
 1
 2<!-- http://www.MyOffice24x7.com / ERMS / FileGuardian -->
 3<!-- Liferay5.1.2 -->
 4<!-- /html/selector/view.jsp -->
 5<!-- hidden portlet, use myoffice_rfidreader_popup(fieldName) javascript call to fetch next RFID from local scanner -->
 6
 7<%@include file="/html/common/init.jsp"%>
 8<script type="text/javascript">
 9var fieldId;
10function myoffice_rfidreader_popup(fieldToModify)
11{
12    fieldId = fieldToModify;
13       var options = {
14      width: 400,
15      modal: true,
16      noCenter: false,
17      title: "<bean:message key="selector.title.scanning"/>"
18    };
19    var message = Liferay.Popup(options);
20    jQuery(message).load(document.rfid_scanner_popup.action);
21}
22</script>
23
24<form name="rfid_scanner_popup" method="post"
25    action="<portlet:actionURL windowState='exclusive'>
26            <portlet:param name='_spage' value='/portlet_action/selector/start'/>
27          </portlet:actionURL>">
28</form>
29
30<logic:notEmpty name="isAdmin">
31<!-- this form is presented to sys admin only, to test RFID scanner during portlet deployment -->
32    <form name="myname" method="post" action="">
33            Test Form  (visible to Admin only)<br/>
34        <input type="text" id="my_test_field_id" name="my_test_field" value="" size="20"/>
35      </form>
36    <a href="#"
37            onclick="javascript:myoffice_rfidreader_popup('my_test_field_id')">
38    <img src="/rfid.observation/html/images/scanner-1.gif" alt="scan"/></a>
39</logic:notEmpty>

When user clicks on scanner-1.gif image, Ajax popup is displayed with main screen greyed-out. In your case, form 'rfid_scanner_popup' may use renderURL instead of actionURL.
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 5, 2009 3:06 PM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Hi Victor,
I tried as you suggested but now facing another problem. My input formbean fields are not read. They are blank.
I see that my Action class (Myreport.java) is invoked but the formbean that this action is associated with in the struts-config.xml never gets populated. I have important pieces of code for your reference. Could you please let me know whats wrong in the code? And why is it that the formBean (ReportBean) associated with the <action> in struts-config.xml is not getting populated with the values entered in the form(InputForm.jsp)????
Here is what I did.
********************************************************************************************************
InputForm.jsp
*********************************************************************************************************
<form name="myReport" action="" method="post">
<input type="text" name="Fname">
<input type="text" name="Lname">
<a href="#" onclick="submitReport()">Submit Report</a>
</form>
<script type="text/javascript">
function submitReport() {
var resultWindow = window.open('<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
<portlet:param name="_spage" value="/portlet_action/Reporting_portlet/Reporting/MyReport"/>"/>
</portlet:actionURL>');
resultWindow .opener = window;
resultWindow .focus();
}
</script>
*********************************************************************************************************
struts-config.xml
*********************************************************************************************************
<form-beans>
<form-bean name="ReportBean" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="Fname" type="java.lang.String"/>
<form-property name="Lname" type="java.lang.String"/>
</form-bean>
<action path="/Reporting_portlet/Reporting/MyReport"
type="com.reporting.MyReport" name="ReportBean" scope="session" validate="true"
input="portlet.Reporting_portlet.ReportRequest">
<forward name="/Reporting_portlet/showReport" path="/portlet_action/Reporting_portlet/showReport" redirect="true"/>
</action>
<action path="/Reporting_portlet/showReport" forward="portlet.Reporting_portlet.showReport"/>
***********************************************************************************************************************
tiles-def.xml
***********************************************************************************************************************
<definition name="portlet.Reporting_portlet.ReportRequest" extends="portlet.Reporting_portlet"> <put name="portlet_content" value="/portlet/Reporting_portlet/InputForm.jsp"/>
</definition>
<definition name="portlet.Reporting_portlet.showReport" extends="portlet.Reporting_portlet"> <put name="portlet_content" value="/portlet/Reporting_portlet/result.jsp"/>
</definition>
************************************************************************************************************************
MyReport.Java
************************************************************************************************************************
public class MyReport extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String Fname = (String) ReportBean.get("Fname");
String Lname = (String) ReportBean.get("Lname");
// I see that Fname and Lname are blank where i try to print them to the console.
.
.
.
return mapping.findForward("/Reporting_portlet/showReport");
}

**********************************************************************************************************************************
Web.xml
**********************************************************************************************************************************
<servlet-mapping>
<servlet-name>Reporting_portlet</servlet-name>
<url-pattern>/Reporting_portlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PortletActionServlet</servlet-name>
<url-pattern>/portlet_action/*</url-pattern>
</servlet-mapping>
***********************************************************************************************************************************
Victor Zorin
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 5, 2009 5:34 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

In your code, submitReport() call is not related to myReport form at all, that's why parameters are not passed.
One of the ways to address it:
 1
 2<form name="myReport"
 3  action="<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
 4          <portlet:param name="_spage" value="/portlet_action/Reporting_portlet/Reporting/MyReport"/>"/>
 5</portlet:actionURL>" method="post">
 6  <input type="text" name="Fname">
 7  <input type="text" name="Lname">
 8  <a href="#" target="new_window" onclick="submitReport()">Submit Report</a>
 9</form>
10<script type="text/javascript">
11function submitReport() {
12  document.myReport.submit();
13}
14</script>

another one, using jQuery, for fun:
 1
 2<form name="myReport"
 3  action="<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
 4          <portlet:param name="_spage" value="/portlet_action/Reporting_portlet/Reporting/MyReport"/>"/>
 5</portlet:actionURL>" method="post">
 6  <input type="text" name="Fname">
 7  <input type="text" name="Lname">
 8  <a href="#" onclick="submitReport()">Submit Report in a Separate Window</a>
 9  <a href="#" onclick="popupReport()">Submit Report in Ajax Popup</a>
10</form>
11<script type="text/javascript">
12function submitReport() {
13  var inputs = jQuery("input, textarea, select", document.myReport);
14  var url = document.myReport.action + "&" + inputs.serialize();
15  var resultWindow = window.open(url);
16  resultWindow .opener = window;
17  resultWindow .focus();
18}
19function popupReport() {
20  var options = (
21  {
22    width: 500;
23    modal: true;
24    title: 'Vivek Report';
25  }
26  var inputs = jQuery("input, textarea, select", document.myReport);
27  var url = document.myReport.action + "&" + inputs.serialize();
28  var message = Lifera.Popup(options);
29  jQuery(message).load(url);
30}
31</script>

Have not tested, but have a look at the approach.
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 9, 2009 2:53 PM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Thanks, Victor,

It worked fine. I have another problem. I have used the same approach to invoke another action that extends DownloadAction. This action successfully writes my report into an excelsheet at the path specified but instead of showing 'File Download' pop-up window with "Do you want to open or save this file?" option it renders the .xls file as text with lot of junk characters. Not able to figure out why its rendering it as text with junk. I have even set the content-type in DownloadAction class to application/vnd.ms-excel(check below). I also see that the file is successfully written into the path specified.

Here is how my action looks

public class DownloadMyReport extends DownloadAction {
protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

String contentType = "application/vnd.ms-excel";

String Fname = (String) ReportBean.get("Fname");
String Lname = (String) ReportBean.get("Lname");

.
expFile = new File("C:\\Reporta\\MyReport.xls");
.
.
return new DownloadAction.FileStreamInfo(contentType, expFile);

}
Victor Zorin
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 9, 2009 5:08 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

Next time, it is better if you post different question in a separate thread, so forum users can relate to it by thread name.

Check first if your web.xml contains mime support for application/vnd.ms-excel.
Vivek N Kapse
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 10, 2009 11:33 AM
Answer

Vivek N Kapse

Rank: Junior Member

Posts: 42

Join Date: September 9, 2008

Recent Posts

Hi Victor,

I had posted a new thread long time back but I didnt not get any replies, as you were very helpful in solving my earlier problem I thought why not post it here again.
I have created a new thread for my DownloadAction problem. Here is the link

DownloadAction problem in struts portlet
Victor Zorin
RE: How to pass request to JSP page using <portlet:renderURL > tag
February 10, 2009 4:43 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

Still, have you checked you web.xml?
After you find the solution, you can post it in this additional thread.