struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laconia Data Systems" <webmas...@laconiadatasystems.com>
Subject Re: Problem with validation (?)
Date Thu, 09 Dec 2004 23:09:06 GMT
Derek-
Any conversions (String to Integer or whatever) need to happen in your
Business Bean layer
e.g.
ActionForm which uses Strings and booleans
private String IntegerDisplay = null;
public String getIntegerDisplay()
{
 return this.IntegerDisplay();
}
public void setDateIntegerDisplay(String display)
{
 this.IntegerDisplay = display;
}

//Business Bean
public class BusinessBean extends BeanUtils
{
//Default constructor as per spec..
 public BusinessBean() { ; }
 public Integer intn = null;
 public String getIntegerDisplay() {
  try
 {
  intn = getInteger();
  if(ConvertUtils.isNull(intn)) return null;
  return intn.toString();
  }
 catch(NumberFormatException d)
 {
  System.out.println("Bad integer has been passed in do something");
 }
 catch(NullPointerException n)
 {
 System.out.println("Null found you passed me a null Integer!");
 }
}//end getIntegerDisplay

public void setIntegerDisplay(String display)
{
 if(display=null) intn = null;
 else
 {
  try
  { //set the value..
   setDisplay(Integer.valueOf(display));
  }
  catch(Throwable t)
  { //exception found set to null
   setDisplay(null);
  }//end catch
 } //end else
}//end setIntegerDisplay
Now what is that about teaching a man to fish?
Hope this helps,
Martin=
----- Original Message ----- 
From: "Wendy Smoak" <java@wendysmoak.com>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Thursday, December 09, 2004 5:02 PM
Subject: Re: Problem with validation (?)


> From: "Derek Broughton" <derek@pointerstop.ca>
>
> > > What happens when somebody types "ABCDE" into your Integer field on
the
> > > form, and it fails validation?  Can you re-display the incorrect user
> input
> > > so they can see what they typed and why it was wrong?
> >
> > Or more concisely, because HTML only has string types.
>
> Oh, sure, take all the fun out of it. ;)  Teach a man to fish, and all...
>
> It begs the question though: is there a case for using Integer in an
> ActionForm?  I know the reasons *not* to (and I don't) but it must be
there
> for a reason?
>
> -- 
> Wendy Smoak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message