portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajiv balchandani <raji...@yahoo.com>
Subject Struts Mapping class return null for getAttributes
Date Thu, 07 Jun 2007 09:23:58 GMT
Hi

Using Jetspeed 2.1 with struts  

My problem is whn my JSP gets submitted  it returns
all getAttribute as null


Can someone please help to whats wrong in the code?
Becoz after redirecting to the same page all
getAttributes are null.

Below is the Code 


---------------JSP Page-----------

<%@ page contentType="text/html;charset=UTF-8"
session="true" %>

<%@ taglib uri="http://struts.apache.org/tags-bean"
prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"
prefix="logic" %>
<%@ taglib
uri="http://portals.apache.org/bridges/struts/tags-portlet-html"
prefix="html" %>

<portlet:defineObjects/>
<%

//response.encodeUrl("");	

//String test = (String)request.getAttribute("TEST");
//out.println("test==="+test);

java.util.ArrayList arr =
(java.util.ArrayList)request.getAttribute("list");
//( i get NULL values )

out.println("arr==="+arr);

java.util.ArrayList arr1 =
(java.util.ArrayList)request.getAttribute("arr");
//( i get NULL values )
out.println("<br>arr==="+arr1);
%>

<html:html>
<head>
<title>test</title>
<link href="/struts-demo/include/formstyle.css"
rel="stylesheet" type="text/css">
<link href="/struts-demo/include/defaultstyle.css"
rel="stylesheet" type="text/css">
</head>
<body text=#000000 bgcolor=#ffffff leftmargin=0
topmargin=0 marginheight="0" marginwidth="0">
<html:form action="/TestPage">
<table border=0 cellpadding=0 cellspacing=0
id="parent">     
<tr>
	<td>User Name:</td>
	<td><html:text property="user_pk" size="16"
maxlength="18"/></TD>
</TR>
<tr>
	<td>User Role:</td>
	<td><html:text property="user_role" size="16"
maxlength="18"/></TD>
</TR>
<tr>
	<td><input type=submit name=submit value=submit></td>
</TR>
</table>

</html:form>

</body>
</html:html>



--------------------------FORM Bean
-------------------------


package fsi.formbean;

import fsi.*;
import fsi.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.sql.*;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



public final class TestForm extends ActionForm {
	private String user_pk				= null;
	private String user_role			= null;

	ArrayList arr = new ArrayList();

	public String getUser_pk() {
       return user_pk;
    }
    public void setUser_pk(String user_pk) {
       	this.user_pk = user_pk;
    }
	public String getUser_role() {
       return user_role;
    }
    public void setUser_role(String user_role) {
       	this.user_role = user_role;
    }	
	public ArrayList getArr() {
       return arr;
    }
    public void setArr(ArrayList arr) {
       	this.arr = arr;
    }	
	
	/**
     * Reset all properties to their default values.
     * @param mapping The mapping used to select this
instance
     * @param request The servlet request we are
processing
     */
    public void reset(ActionMapping mapping,
HttpServletRequest request){
	   user_pk				= null;
	   user_role			= null;
	   arr = null;
    }
}	 


------------------------------------------------------------------------------------------------


--------------------------Action
Bean----------------------------------


package fsi.actionbean;

import fsi.*;
import fsi.formbean.*;
import fsi.modelbean.*;
import java.util.ArrayList;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;


public final class TestAction extends Action {

public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception {

		HttpSession session = request.getSession();

		String userpk = request.getParameter("user_pk");
		String userrole = request.getParameter("user_role");


	
System.out.println("userpk=="+userpk+"==userrole=="+userrole);


		ArrayList list = new ArrayList();	

		list.add("Rajiv");
		list.add("Rajiv1");
		list.add("Rajiv2");
		
		if(userpk != null)
		{
			request.setAttribute("list",list);			
			System.out.println("Value Set");
			((TestForm)form).setArr(list);
		}

		return mapping.findForward("success");
    }
}


----------------------------------------------------------------------------------------------------


----------------------------Struts-Config.xml---------------------------------------------------------

<form-bean name="TestForm"
type="fsi.formbean.TestForm" />



      <action path="/TestPageSucc"
forward="/WEB-INF/view/Test.jsp" name="TestForm" />

      <action path="/TestPage"
type="fsi.actionbean.TestAction"  name="TestForm"
scope="session" input="/WEB-INF/view/Test.jsp" >	     
      
	    <forward name="success" path="/TestPageSucc.do"
redirect="false"/>
      </action>


--------------------------------------------------------------------------------------------------------------------------------


------------------------------------------web.xml-------------------------------------------------------------------


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

 <resource-ref>
      <description>FSI WF Connection</description>
      <res-ref-name>jdbc/MSSQLDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

  <display-name>Struts Example Portlet
Application</display-name>
  <servlet>
    <servlet-name>action</servlet-name>
<!--   
<servlet-class>org.apache.portals.bridges.struts.PortletServlet</servlet-class>-->
   
<servlet-class>fsi.actionbean.FSIActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml,
/WEB-INF/struts-config-registration.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>9</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>9</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>JetspeedContainer</servlet-name>
    <display-name>Jetspeed Container</display-name>
    <description>MVC Servlet for Jetspeed Portlet
Applications</description>
   
<servlet-class>org.apache.jetspeed.container.JetspeedContainerServlet</servlet-class>
    <init-param>
      <param-name>contextName</param-name>
      <param-value>struts-demo</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>JetspeedContainer</servlet-name>
    <url-pattern>/container/*</url-pattern>
  </servlet-mapping>
  <!-- The Welcome File List -->
  <welcome-file-list>
   
<welcome-file>WEB-INF/view/welcome.jsp</welcome-file>
  </welcome-file-list>
  <!-- The default error page -->
  <error-page>
   
<exception-type>java.lang.Exception</exception-type>
    <location>/WEB-INF/view/Error.jsp</location>
  </error-page>
  <!-- Application Tag Library Descriptor -->
  <taglib>
    <taglib-uri>/tags/app</taglib-uri>
   
<taglib-location>/WEB-INF/app.tld</taglib-location>
  </taglib>
  <taglib>
   
<taglib-uri>http://java.sun.com/portlet</taglib-uri>
   
<taglib-location>/WEB-INF/tld/portlet.tld</taglib-location>
  </taglib>
</web-app>



--------------------------------------------------------------------------------------------------------------------------------




 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message