RE: getting validation errors on initial display of a form

2002-03-25 Thread Dave Newton

Don't go to the action page (the .do), go to the .jsp page! The action
is just the target of the form, not the page you start from.

(At least that's what I've figured out?!)

Dick Starr said:
> My problem is that when I execute my form via 
> http://localhost:8080/starrd/app/names.do I get validation errors 
> appearing immediately (before I enter any data in the form). I can't 
> believe thats normal: I must be doing something wrong.

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: getting validation errors on initial display of a form

2002-03-25 Thread Dimitar Stavrakov

In the struts-config.xml try setting validate="false" for the initial action
names and then set it to true for the submit action on the form of the
names.jsp . This will disable the validate() call when the form is first
initialized :

  

  



-Original Message-
From: Dick Starr [mailto:[EMAIL PROTECTED]] 
Sent: Monday, January 21, 2002 9:20 PM
To: struts-user
Subject: getting validation errors on initial display of a form

I am new to Struts and am using Ted's sample logon app as my basis for
learning. His part works fine. I added a new jsp page that contains two
fields, created a form bean & an action form with validation edits. My
problem is that when I execute my form via
http://localhost:8080/starrd/app/names.do I get validation errors appearing
immediately (before I enter any data in the form). I can't believe thats
normal: I must be doing something wrong.

Thanks in advance for the help.

Dick Starr

Here's the pertinent parts of my struts-config:

  
  

  


  

  


Here's my Name.jsp:


<%@ page language="java" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>






Name:
  

Address line one:
  









<%--

Allow user to submit username and password to logon action.

--%>

Here's the pertinent parts of SANameAction.java:

public final class SANameAction extends Action
{
  public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
  {
// Obtain fields from web tier
String name = ((SANameForm) form).getName();
String addr1 = ((SANameForm) form).getAddr1();

// Log this event, if appropriate
if (servlet.getDebug() >= SAConstants.DEBUG)
{
  StringBuffer message =
new StringBuffer("SANameAction: name = ");
  message.append(name);
  message.append(", addr1 = ");
  message.append(addr1);
  servlet.log(message.toString());
}

// Forward control to the welcome URI
// specified in the configuration.
return (mapping.findForward(SAConstants.WELCOME));
  }

} // End SANameAction

Here's the pertinent parts of SANameForm.java:

public final class SANameForm extends ActionForm
{
  //  Instance Variables

  private String name = null;
  private String addr1 = null;

  //  Properties

  public String getName()
  {
return (this.name);
  }

  public void setName(String name)
  {
this.name = name;
  }

  public String getAddr1()
  {
return (this.addr1);
  }

  public void setAddr1(String addr1)
  {
this.addr1 = addr1;
  }

//  Public Methods
public void reset(ActionMapping mapping,
HttpServletRequest request)
{
  setName(null);
  setAddr1(null);
}

public ActionErrors validate(ActionMapping mapping,
 HttpServletRequest request)
{
  ActionErrors errors = new ActionErrors();
  if ((name == null) || (name.length() < 1))
errors.add("name",
  new ActionError("app.error.name.required"));
  if ((addr1 == null) || (addr1.length() < 1))
errors.add("addr1",
  new ActionError("app.error.addr1.required"));
  return errors;
}

} // End SANameForm

When I first execute the form via  http://localhost:8080/starrd/app/names.do
I immediately (before entering any data or executing the submit button) I
get validation errors displayed for name and addr1 and get the following in
my log file:

2002-01-21 20:19:19 action: Processing a GET for /app/names
2002-01-21 20:19:19 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:19 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:19 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:19 action:  Populating bean properties from this request
2002-01-21 20:19:19 action:  Validating input form properties
2002-01-21 20:19:19 action:   Validation error(s), redirecting to:
/pages/app/Name.jsp

Then if I fill in the two fields with data, I do not get validation errors
(which is correct). Then this is what is in my log:

2002-01-21 20:19:37 action: Processing a POST for /app/names
2002-01-21 20:19:37 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:37 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:37 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:37 action:  Populating bean properties from this request
2002-01-21 20:19:37 action:  Va

Re: getting validation errors on initial display of a form

2002-03-23 Thread Anant Sagar

Since you are calling "names.do"   directly, formbean calls validate() method before 
forwarding to appropriate action class and hence the erros are displayed.
Call your form using this  http://localhost:8080/starrd/pages/app/Name.jsp   initially 
 
and set action="/app/names" while  submitting. 
Hope that may help .

Anant Sagar

- Original Message - 
From: "Dick Starr" <[EMAIL PROTECTED]>
To: "struts-user" <[EMAIL PROTECTED]>
Sent: Tuesday, January 22, 2002 8:50 AM
Subject: getting validation errors on initial display of a form


> I am new to Struts and am using Ted's sample logon app as my basis for
> learning. His part works fine. I added a new jsp page that contains two
> fields, created a form bean & an action form with validation edits. My
> problem is that when I execute my form via
> http://localhost:8080/starrd/app/names.do I get validation errors appearing
> immediately (before I enter any data in the form). I can't believe thats
> normal: I must be doing something wrong.
> 
> Thanks in advance for the help.
> 
> Dick Starr
> 
> Here's the pertinent parts of my struts-config:
> 
>   
>name="nameForm"
> type="com.starrcs.app.SANameForm"/>
> 
>   
>name="names"
>   path="/app/names.do"/>
> 
>   
>path="/app/names"
>   type="com.starrcs.app.SANameAction"
>   name="nameForm"
>   scope="request"
>   validate="true"
>   input="/pages/app/Name.jsp">
>name="continue"
> path="/pages/app/Name.jsp"/>
> 
> 
> Here's my Name.jsp:
> 
> 
> <%@ page language="java" %>
> <%@ taglib uri="/tags/struts-bean" prefix="bean" %>
> <%@ taglib uri="/tags/struts-html" prefix="html" %>
> 
> 
> 
> 
> 
> 
> Name:
>   
> 
> Address line one:
>   
> 
> 
> 
> 
> 
> 
> 
> 
> 
> <%--
> 
> Allow user to submit username and password to logon action.
> 
> --%>
> 
> Here's the pertinent parts of SANameAction.java:
> 
> public final class SANameAction extends Action
> {
>   public ActionForward perform(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException
>   {
> // Obtain fields from web tier
> String name = ((SANameForm) form).getName();
> String addr1 = ((SANameForm) form).getAddr1();
> 
> // Log this event, if appropriate
> if (servlet.getDebug() >= SAConstants.DEBUG)
> {
>   StringBuffer message =
> new StringBuffer("SANameAction: name = ");
>   message.append(name);
>   message.append(", addr1 = ");
>   message.append(addr1);
>   servlet.log(message.toString());
> }
> 
> // Forward control to the welcome URI
> // specified in the configuration.
> return (mapping.findForward(SAConstants.WELCOME));
>   }
> 
> } // End SANameAction
> 
> Here's the pertinent parts of SANameForm.java:
> 
> public final class SANameForm extends ActionForm
> {
>   //  Instance Variables
> 
>   private String name = null;
>   private String addr1 = null;
> 
>   //  Properties
> 
>   public String getName()
>   {
> return (this.name);
>   }
> 
>   public void setName(String name)
>   {
> this.name = name;
>   }
> 
>   public String getAddr1()
>   {
> return (this.addr1);
>   }
> 
>   public void setAddr1(String addr1)
>   {
> this.addr1 = addr1;
>   }
> 
> //  Public Methods
> public void reset(ActionMapping mapping,
> HttpServletRequest request)
> {
>   setName(null);
>   setAddr1(null);
> }
> 
> public ActionErrors validate(ActionMapping mapping,
>  HttpServletRequest request)
> {
>   ActionErrors errors = new ActionErrors();
>   if ((name == null) || (name.length() < 1))
> errors.add("name",
>   new ActionError("app.error.name.required"));
>   if ((addr1 == null) || (addr1.length() < 1))
> errors.add("addr1",
>   new ActionError("app.error.addr1.required"));
>   return errors;
> }
> 
> } // End SANameForm
> 
> When I first execute the form via  http://localhost:8080/starrd/app/names.do
> I i

getting validation errors on initial display of a form

2002-03-23 Thread Dick Starr

I am new to Struts and am using Ted's sample logon app as my basis for
learning. His part works fine. I added a new jsp page that contains two
fields, created a form bean & an action form with validation edits. My
problem is that when I execute my form via
http://localhost:8080/starrd/app/names.do I get validation errors appearing
immediately (before I enter any data in the form). I can't believe thats
normal: I must be doing something wrong.

Thanks in advance for the help.

Dick Starr

Here's the pertinent parts of my struts-config:

  
  

  


  

  


Here's my Name.jsp:


<%@ page language="java" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>






Name:
  

Address line one:
  









<%--

Allow user to submit username and password to logon action.

--%>

Here's the pertinent parts of SANameAction.java:

public final class SANameAction extends Action
{
  public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
  {
// Obtain fields from web tier
String name = ((SANameForm) form).getName();
String addr1 = ((SANameForm) form).getAddr1();

// Log this event, if appropriate
if (servlet.getDebug() >= SAConstants.DEBUG)
{
  StringBuffer message =
new StringBuffer("SANameAction: name = ");
  message.append(name);
  message.append(", addr1 = ");
  message.append(addr1);
  servlet.log(message.toString());
}

// Forward control to the welcome URI
// specified in the configuration.
return (mapping.findForward(SAConstants.WELCOME));
  }

} // End SANameAction

Here's the pertinent parts of SANameForm.java:

public final class SANameForm extends ActionForm
{
  //  Instance Variables

  private String name = null;
  private String addr1 = null;

  //  Properties

  public String getName()
  {
return (this.name);
  }

  public void setName(String name)
  {
this.name = name;
  }

  public String getAddr1()
  {
return (this.addr1);
  }

  public void setAddr1(String addr1)
  {
this.addr1 = addr1;
  }

//  Public Methods
public void reset(ActionMapping mapping,
HttpServletRequest request)
{
  setName(null);
  setAddr1(null);
}

public ActionErrors validate(ActionMapping mapping,
 HttpServletRequest request)
{
  ActionErrors errors = new ActionErrors();
  if ((name == null) || (name.length() < 1))
errors.add("name",
  new ActionError("app.error.name.required"));
  if ((addr1 == null) || (addr1.length() < 1))
errors.add("addr1",
  new ActionError("app.error.addr1.required"));
  return errors;
}

} // End SANameForm

When I first execute the form via  http://localhost:8080/starrd/app/names.do
I immediately (before entering any data or executing the submit button) I
get validation errors displayed for name and addr1 and get the following in
my log file:

2002-01-21 20:19:19 action: Processing a GET for /app/names
2002-01-21 20:19:19 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:19 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:19 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:19 action:  Populating bean properties from this request
2002-01-21 20:19:19 action:  Validating input form properties
2002-01-21 20:19:19 action:   Validation error(s), redirecting to:
/pages/app/Name.jsp

Then if I fill in the two fields with data, I do not get validation errors
(which is correct). Then this is what is in my log:

2002-01-21 20:19:37 action: Processing a POST for /app/names
2002-01-21 20:19:37 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:37 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:37 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:37 action:  Populating bean properties from this request
2002-01-21 20:19:37 action:  Validating input form properties
2002-01-21 20:19:37 action:   No errors detected, accepting input
2002-01-21 20:19:37 action:  Looking for Action instance for class
com.starrcs.app.SANameAction
2002-01-21 20:19:37 action: SANameAction: name = data1, addr1 = data2
2002-01-21 20:19:37 action: Processing a POST for /app/welcome
2002-01-21 20:19:37 action:  Looking for Action instance for class
com.starrcs.app.SAContinueAction



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: getting validation errors on initial display of a form

2002-01-22 Thread Witt, Mike (OH35)

I'm pretty new to struts also, but here is what I've found:

If you set validate to true in the action mapping, the validation will 
run before the action.  If you set it to false, you may run the validate 
method of the form yourself at any time.  Also, it is interesting to note 
that if you forward to a .jsp, it only runs the action the first time, 
successive forwards to the jsp do not run the action.  In order to run 
the action, you usually want to forward to the action (/do/myAction).

In my situation, I had a form which I initially wanted to fill with data 
for editing, and then take the data and update the database.  To do 
this, I set up one action with two action mappings.  The first action 
mapping was to load the data and the second to take the data and update 
the database.  The first action mapping, I set validate to false and 
the second I set validate to true.  I also used the param attribute of 
the action within the struts config to set these differently depending 
on the action (so that my servlet could tell which action I was doing.  

Here is some sample stuff:

struts-config actions:


  



  


In my message_edit.jsp, I have:



HTH and it's probably not perfect, but it works,

Mike Witt

-Original Message-
From: Dick Starr [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 22, 2002 8:51 AM
To: struts-user
Subject: getting validation errors on initial display of a form


I am new to Struts and am using Ted's sample logon app as my basis for
learning. His part works fine. I added a new jsp page that contains two
fields, created a form bean & an action form with validation edits. My
problem is that when I execute my form via
http://localhost:8080/starrd/app/names.do I get validation errors appearing
immediately (before I enter any data in the form). I can't believe thats
normal: I must be doing something wrong.

Thanks in advance for the help.

Dick Starr

Here's the pertinent parts of my struts-config:

  
  

  


  

  


Here's my Name.jsp:


<%@ page language="java" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>






Name:
  

Address line one:
  









<%--

Allow user to submit username and password to logon action.

--%>

Here's the pertinent parts of SANameAction.java:

public final class SANameAction extends Action
{
  public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
  {
// Obtain fields from web tier
String name = ((SANameForm) form).getName();
String addr1 = ((SANameForm) form).getAddr1();

// Log this event, if appropriate
if (servlet.getDebug() >= SAConstants.DEBUG)
{
  StringBuffer message =
new StringBuffer("SANameAction: name = ");
  message.append(name);
  message.append(", addr1 = ");
  message.append(addr1);
  servlet.log(message.toString());
}

// Forward control to the welcome URI
// specified in the configuration.
return (mapping.findForward(SAConstants.WELCOME));
  }

} // End SANameAction

Here's the pertinent parts of SANameForm.java:

public final class SANameForm extends ActionForm
{
  //  Instance Variables

  private String name = null;
  private String addr1 = null;

  //  Properties

  public String getName()
  {
return (this.name);
  }

  public void setName(String name)
  {
this.name = name;
  }

  public String getAddr1()
  {
return (this.addr1);
  }

  public void setAddr1(String addr1)
  {
this.addr1 = addr1;
  }

//  Public Methods
public void reset(ActionMapping mapping,
HttpServletRequest request)
{
  setName(null);
  setAddr1(null);
}

public ActionErrors validate(ActionMapping mapping,
 HttpServletRequest request)
{
  ActionErrors errors = new ActionErrors();
  if ((name == null) || (name.length() < 1))
errors.add("name",
  new ActionError("app.error.name.required"));
  if ((addr1 == null) || (addr1.length() < 1))
errors.add("addr1",
  new ActionError("app.error.addr1.required"));
  return errors;
}

} // End SANameForm

When I first execute the form via  http://localhost:8080/starrd/app/names.do
I immediately (before entering any data or executing the submit button)
get validation errors displayed for name and addr1 and get the following in
my log file:

2002-01-21 20:19:19 action: Processing a GET for /app/names
2002-01-21 20:19:19 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:19 action:  Creating new ActionForm in

getting validation errors on initial display of a form

2002-01-22 Thread Dick Starr

I am new to Struts and am using Ted's sample logon app as my basis for
learning. His part works fine. I added a new jsp page that contains two
fields, created a form bean & an action form with validation edits. My
problem is that when I execute my form via
http://localhost:8080/starrd/app/names.do I get validation errors appearing
immediately (before I enter any data in the form). I can't believe thats
normal: I must be doing something wrong.

Thanks in advance for the help.

Dick Starr

Here's the pertinent parts of my struts-config:

  
  

  


  

  


Here's my Name.jsp:


<%@ page language="java" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>






Name:
  

Address line one:
  









<%--

Allow user to submit username and password to logon action.

--%>

Here's the pertinent parts of SANameAction.java:

public final class SANameAction extends Action
{
  public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
  {
// Obtain fields from web tier
String name = ((SANameForm) form).getName();
String addr1 = ((SANameForm) form).getAddr1();

// Log this event, if appropriate
if (servlet.getDebug() >= SAConstants.DEBUG)
{
  StringBuffer message =
new StringBuffer("SANameAction: name = ");
  message.append(name);
  message.append(", addr1 = ");
  message.append(addr1);
  servlet.log(message.toString());
}

// Forward control to the welcome URI
// specified in the configuration.
return (mapping.findForward(SAConstants.WELCOME));
  }

} // End SANameAction

Here's the pertinent parts of SANameForm.java:

public final class SANameForm extends ActionForm
{
  //  Instance Variables

  private String name = null;
  private String addr1 = null;

  //  Properties

  public String getName()
  {
return (this.name);
  }

  public void setName(String name)
  {
this.name = name;
  }

  public String getAddr1()
  {
return (this.addr1);
  }

  public void setAddr1(String addr1)
  {
this.addr1 = addr1;
  }

//  Public Methods
public void reset(ActionMapping mapping,
HttpServletRequest request)
{
  setName(null);
  setAddr1(null);
}

public ActionErrors validate(ActionMapping mapping,
 HttpServletRequest request)
{
  ActionErrors errors = new ActionErrors();
  if ((name == null) || (name.length() < 1))
errors.add("name",
  new ActionError("app.error.name.required"));
  if ((addr1 == null) || (addr1.length() < 1))
errors.add("addr1",
  new ActionError("app.error.addr1.required"));
  return errors;
}

} // End SANameForm

When I first execute the form via  http://localhost:8080/starrd/app/names.do
I immediately (before entering any data or executing the submit button)
get validation errors displayed for name and addr1 and get the following in
my log file:

2002-01-21 20:19:19 action: Processing a GET for /app/names
2002-01-21 20:19:19 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:19 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:19 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:19 action:  Populating bean properties from this request
2002-01-21 20:19:19 action:  Validating input form properties
2002-01-21 20:19:19 action:   Validation error(s), redirecting to:
/pages/app/Name.jsp

Then if I fill in the two fields with data, I do not get validation errors
(which is correct). Then this is what is in my log:

2002-01-21 20:19:37 action: Processing a POST for /app/names
2002-01-21 20:19:37 action:  Looking for ActionForm bean under attribute
'nameForm'
2002-01-21 20:19:37 action:  Creating new ActionForm instance of class
'com.starrcs.app.SANameForm'
2002-01-21 20:19:37 action:  Storing instance under attribute 'nameForm' in
scope 'request'
2002-01-21 20:19:37 action:  Populating bean properties from this request
2002-01-21 20:19:37 action:  Validating input form properties
2002-01-21 20:19:37 action:   No errors detected, accepting input
2002-01-21 20:19:37 action:  Looking for Action instance for class
com.starrcs.app.SANameAction
2002-01-21 20:19:37 action: SANameAction: name = data1, addr1 = data2
2002-01-21 20:19:37 action: Processing a POST for /app/welcome
2002-01-21 20:19:37 action:  Looking for Action instance for class
com.starrcs.app.SAContinueAction



--
To unsubscribe, e-mail:   
For additional commands, e-mail: