aspose file tools*
The moose likes Portals and Portlets and the fly likes Not able to send data from one struts portlet to another struts portlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Not able to send data from one struts portlet to another struts portlet" Watch "Not able to send data from one struts portlet to another struts portlet" New topic
Author

Not able to send data from one struts portlet to another struts portlet

Bharath Gowda
Greenhorn

Joined: Apr 15, 2008
Posts: 17
Hi,

I'm new to portlet development. I'm trying to send data from one struts portlet to another struts portlet but it is giving error.

struts-config.xml
************************************
<!-- Form Beans -->
<form-beans>
<form-bean name="SelectForm" type="com.gdnindia.strutsnav.forms.SelectForm">
</form-bean>
</form-beans>

<!-- Global Exceptions -->
<global-exceptions>
</global-exceptions>

<!-- Global Forwards -->
<global-forwards>
</global-forwards>

<!-- Action Mappings -->
<action-mappings>
<action path="/SendData" type="com.gdnindia.strutsnav.actions.SendDataAction" name="SelectForm" scope="request">
<forward contextRelative="false" name="success" path="/successpage.jsp">
</forward>
</action>
</action-mappings>
***********************************************
index.jsp
********************************************
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<portlet efineObjects/>
<h3><br>
Select a Team:</h3>
<html:form action="/SendData">
<html:select property="selectedItem" onchange="this.form.submit();">
<html ption value="TeamA">Team A</html ption>
<html ption value="TeamB">Team B</html ption>
<html ption value="TeamC">Team C</html ption>
<html ption value="TeamD">Team D</html ption>
<table>
<tbody>

<tr>
<td align="left">SelectedItem:</td>
<td><c ut value="${sessionScope.selectedItem}" /></td>
</tr>

</tbody>
</table>
</html:select>
</html:form>
**********************************
successpage.jsp
************************************
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@page import="javax.portlet.PortletSession"%>

<portlet efineObjects />
<% PortletSession s = renderRequest.getPortletSession();
String data = (String) s.getAttribute("javax.portlet.request");
if (data == null || data.length() == 0)
data = "no data found"; %>
<h3>Team selected is:</h3>
<table>
<tbody>

<tr>
<td align="left">SelectedItem:</td>
<td><c ut value="${data}" /></td>
</tr>

</tbody>

</table>
***************************************
SendDataAction.java
**************************************
public class SendDataAction extends StrutsAction implements IStrutsPrepareRender

{

public ActionForward execute(ActionMapping mapping, ActionForm form, PortletRequest request, PortletResponse response)
throws Exception {

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward(); // return value

try {
System.out.println(" ---- Entering SendDataAction to retrive the value---");

PortletSession psession = request.getPortletSession();
//RenderRequest pReq = (RenderRequest) request
//.getAttribute("javax.portlet.request");
RenderResponse rRes = (RenderResponse) request
.getAttribute("javax.portlet.response");
//PortletConfig portletConfig = (PortletConfig) request.getAttribute("javax.portlet.config");

String teamname = request.getParameter("selectedItem");
System.out.println("***Team Name VALUE ***" + teamname);
psession.getAttribute("selectedItem", psession.APPLICATION_SCOPE);
System.out.println("***Team Name VALUE ***" + psession.getAttribute("selectedItem", psession.APPLICATION_SCOPE));
rRes.getPortletOutputStream();
System.out.println("***Leaving SendDataAction to retrive the value***");

} catch (Exception e) {

**************************************
SelectForm.java
************************************
public class SelectForm extends ActionForm

{

/**
*
*/
private static final long serialVersionUID = -6313074275445304102L;
private String SelectedItem = null;

/**
* Get SelectedItem
* @return String
*/
public String getSelectedItem() {
return SelectedItem;
}

/**
* Set SelectedItem
* @param <code>String</code>
*/
public void setSelectedItem(String s) {
this.SelectedItem = s;
}

}
**************************

I'm trying to do this from 2 days. but i'm getting "400 Invalid path /SendData was requested" error...I'm going crazy, Please let me know what is wrong with the implementation. I'm using IBM RAD 7.0, Websphere portal 6.0 server

Or if you have any sample code to implement this, please share it with me.


Bharath PU<br />SCJP - 1.4 <br />IBM Certified Database Associate<br />IBM Certified Advanced Application Developer -- Rational Application Developer for WebSphere Software V6.0
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Typically, porlets can't talk to each other. If they are in a common war, they can share information through the APPLICATION_SCOPE of the Session, but even that can be tricky with a Struts portlet.

If your portlets are packaged in separate war files, standard development won't allow them to communicate. You need to roll your own solution. A shared database table is a common way to allow portlets to share information. For IBM Portlets, you can use the PortletService.

-Cameron McKenzie
Bharath Gowda
Greenhorn

Joined: Apr 15, 2008
Posts: 17
Thanks Cameron. We decided to use JSR 168 basic portlets instead of using struts portlets.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to send data from one struts portlet to another struts portlet
 
Similar Threads
Sending collection to Action
JSP Struts/JSTL Form problem
no getter method
Editing and submitting multiple records
Cannot retrieve mapping for action