struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Winterfeldt <dwinterfe...@yahoo.com>
Subject Re: validate() interaction with OptionsTag.getIterator(OptionsTag) - NullPointerException
Date Wed, 15 Aug 2001 21:26:08 GMT
It looks like you are clearing your list in the reset
method of your ActionForm.  The first time the form is
loaded the list is created in the constructor, but
then reset is called and your validation fails so you
are sent back to the jsp page again and then list is
null.  Either don't set list to null in the reset
method or prepare the list in it's method instead of
in the constructor.

David

--- David Mirly <davidm@wrq.com> wrote:
> I have a simple for with a text input field, submit
> button and select
> components
> in the form.
> 
> There is a corresponding ActionForm and Action
> class.
> 
> If I don't populate the ActionErrors object in
> validate, everything works
> great.
> 
> If I do populate the ActionErrors object, I get a
> NullPointerException in
> the browser like so:
> 
> java.lang.NullPointerException
> 	at
>
org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:366)
> 
> Not that it matters, but I am validating the text
> input field only.
> 
> If I comment out the select component in the JSP
> page and put an invalid
> entry in
> the text field, the error shows up fine.
> 
> I don't see the relationship between these two
> things.
> 
> Here is the code in its entirety.
> 
> Much obliged.
> 
> David
> 
>
----------------------------------------------------------------------------
> -------------------------------------------
> 
> <struts-config>
> 
>   <!-- ========== Form Bean Definitions
> ===================================
> -->
>   <form-beans>
> 
>     <!-- meter form bean -->
>     <form-bean      name="meterForm"
>                     type="rwebstruts.MeterForm"/>
> 
>   </form-beans>
> 
> 
>   <!-- ========== Global Forward Definitions
> ==============================
> -->
>   <global-forwards>
>     <forward   name="meter"               
> path="/meter.jsp"/>
>   </global-forwards>
> 
> 
>   <!-- ========== Action Mapping Definitions
> ==============================
> -->
>   <action-mappings>
> 
>     <!-- Process a MeterHost addition/removal -->
>     <action    path="/meter"
>                type="rwebstruts.MeterAction"
>                name="meterForm"
>               scope="request"
>               input="/meter.jsp">
>     </action>
> 
>   </action-mappings>
> 
> </struts-config>
> 
>
----------------------------------------------------------------------------
>
---------------------------------------------------------
> 
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld"
> prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld"
> prefix="html" %>
> 
> <html:html locale="true">
> <head>
> <title><bean:message key="logon.title"/></title>
> <html:base/>
> </head>
> <body bgcolor="white">
> 
> <html:errors/>
> 
> <html:form action="/meter">
> <table border="0" width="100%">
> 
>   <tr>
>     <th align="right">
>       <bean:message key="prompt.host"/>
>     </th>
>     <td align="left">
>       <html:text property="host" size="16"
> maxlength="16"/>
>     </td>
>   </tr>
> 
>   <tr>
>     <th align="right">
>       <bean:message key="prompt.port"/>
>     </th>
>     <td align="left">
>       <html:text property="port" size="6"
> maxlength="6"/>
>     </td>
>   </tr>
> 
>   <tr>
>     <td align="right">
>       <html:submit property="add" value="Add"/>
>     </td>
>     <td align="left">
>       <html:submit property="remove"
> value="Remove"/>
>     </td>
>   </tr>
> 
>   <tr>
> 	<td align="right">
> 		<html:select property="selectedHost" size="10">
> 			<html:options property="list"/>
> 		</html:select>
> 	</td>
>   </tr>
> 
> </table>
> 
> </html:form>
> 
> </body>
> </html:html>
> 
> 
> 
>
----------------------------------------------------------------------------
> -------------------------------------------
> 
> 
> package rwebstruts;
> 
> 
> import javax.servlet.http.HttpServletRequest;
> import java.util.*;
> import org.apache.struts.action.ActionError;
> import org.apache.struts.action.ActionErrors;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionMapping;
> 
> public final class MeterForm extends ActionForm {
> 
>     private String host = null;
> 
>     private String port = null;
> 
>     private ArrayList list;
> 
> 	private String selectedHost = null;
> 
> 
> 	public MeterForm() {
> 		list = new ArrayList();
> 		ConfProp props = new ConfProp();
> 		Vector v = props.getMeterHosts();
> 		for (int i=0; i<v.size(); i++)
> 			list.add(v.elementAt(i));
> 		setList(list);
> 	}
> 
> 
>     public String getHost() {
> 
> 	return (this.host);
> 
>     }
> 
> 
>     public void setHost(String host) {
> 
>         this.host = host;
> 
>     }
> 
> 
>     public String getPort() {
> 
> 	return (this.port);
> 
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Mime
View raw message