You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Engbers, ir. J.B.O.M." <J....@dlg.agro.nl> on 2003/12/16 10:11:35 UTC

Retrieving boolean properties from a DynaActionForm

Hi,

I have defined a boolean property in a DynaActionForm ("volledig" which
means complete).

The value should be checked in the validate()-method.
It is easy to retrieve String-properties from the hash-map but the compiler
does not accept the following construct:
  	if ((boolean)this.get("volledig"))
complaining that it :Cannot cast from Object to boolean.

How can I use this boolean value?

Ben

public class ZoekDynaActionForm extends DynaActionForm {
	public ZoekDynaActionForm() {
		super();
	}

	private Zoek data;	    
	public void setData	  (Zoek data)	{this.data=data;}
	public Zoek getData() {return this.data;}

	protected boolean NullOfLeeg (String str){
	  return ((str == null) || (str.length() == 0));
	}	
	public void reset(ActionMapping mapping, HttpServletRequest request)
{
	  this.data = new Zoek();
	}	
	public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)	{
	  ActionErrors errors = new ActionErrors();
	  if ("1".equals((String)this.get("selectie"))) {
		if
("".equals((String)this.get("gemeente"))&&"".equals((String)this.get("sectie
"))&&"".equals((String)this.get("perceel"))) {
		  errors.add("Perceelkeuze", new
ActionError("error.Perceelkeuze"));
		} else {
			if (NullOfLeeg((String)this.get("gemeente")))
errors.add("Gemeente", new ActionError("error.gemeente.verplicht")) ;
			if (NullOfLeeg((String)this.get("sectie")))
errors.add("Sectie", new ActionError("error.sectie.verplicht"));
			if (NullOfLeeg((String)this.get("perceel")))
errors.add("Perceel", new ActionError("error.perceel.verplicht"));
		}
	  }
	  
	  if ("2".equals((String)this.get("selectie"))) {
==>	  	if ((boolean)this.get("volledig")) {
			errors.add("Volledige naam", new
ActionError("error.naam.volledig"));
		} else {
			errors.add("Beginletters", new
ActionError("error.naam.deel"));
		}
	  }
	  return (errors);
	}
}


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


Re: Retrieving boolean properties from a DynaActionForm

Posted by Martin Gainty <mg...@hotmail.com>.
Instantiated Objects cannot be primitive type and vice-versa
you CAN compare one object to another object or an object to a null object/
-Martin
----- Original Message ----- 
From: "Engbers, ir. J.B.O.M." <J....@dlg.agro.nl>
To: <st...@jakarta.apache.org>
Sent: Tuesday, December 16, 2003 4:11 AM
Subject: Retrieving boolean properties from a DynaActionForm


> Hi,
>
> I have defined a boolean property in a DynaActionForm ("volledig" which
> means complete).
>
> The value should be checked in the validate()-method.
> It is easy to retrieve String-properties from the hash-map but the
compiler
> does not accept the following construct:
>   if ((boolean)this.get("volledig"))
> complaining that it :Cannot cast from Object to boolean.
>
> How can I use this boolean value?
>
> Ben
>
> public class ZoekDynaActionForm extends DynaActionForm {
> public ZoekDynaActionForm() {
> super();
> }
>
> private Zoek data;
> public void setData   (Zoek data) {this.data=data;}
> public Zoek getData() {return this.data;}
>
> protected boolean NullOfLeeg (String str){
>   return ((str == null) || (str.length() == 0));
> }
> public void reset(ActionMapping mapping, HttpServletRequest request)
> {
>   this.data = new Zoek();
> }
> public ActionErrors validate(ActionMapping mapping,
> HttpServletRequest request) {
>   ActionErrors errors = new ActionErrors();
>   if ("1".equals((String)this.get("selectie"))) {
> if
>
("".equals((String)this.get("gemeente"))&&"".equals((String)this.get("sectie
> "))&&"".equals((String)this.get("perceel"))) {
>   errors.add("Perceelkeuze", new
> ActionError("error.Perceelkeuze"));
> } else {
> if (NullOfLeeg((String)this.get("gemeente")))
> errors.add("Gemeente", new ActionError("error.gemeente.verplicht")) ;
> if (NullOfLeeg((String)this.get("sectie")))
> errors.add("Sectie", new ActionError("error.sectie.verplicht"));
> if (NullOfLeeg((String)this.get("perceel")))
> errors.add("Perceel", new ActionError("error.perceel.verplicht"));
> }
>   }
>
>   if ("2".equals((String)this.get("selectie"))) {
> ==>   if ((boolean)this.get("volledig")) {
> errors.add("Volledige naam", new
> ActionError("error.naam.volledig"));
> } else {
> errors.add("Beginletters", new
> ActionError("error.naam.deel"));
> }
>   }
>   return (errors);
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

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


from sathish:regarding locale

Posted by Sathish Babu K R <kr...@yahoo.com>.
hi all

in our coy we have decided to implement
internationalization using Locale...

can anybody give some idea abt to start with,like
needed files,configurations,usage in jsp/java files.

regards
sathish

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

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


Re: Retrieving boolean properties from a DynaActionForm

Posted by Pedro Salgado <sa...@04web.com>.
Hi!

Try this:
        
        Boolean bVolledig = Boolean.valueOf((String)form.get("volledig"));
        boolean volledig = bVolledig.booleanValue();


Should work

Pedro Salgado


On 16/12/2003 09:11, "Engbers, ir. J.B.O.M." <J....@dlg.agro.nl>
wrote:

> Hi,
> 
> I have defined a boolean property in a DynaActionForm ("volledig" which
> means complete).
> 
> The value should be checked in the validate()-method.
> It is easy to retrieve String-properties from the hash-map but the compiler
> does not accept the following construct:
> if ((boolean)this.get("volledig"))
> complaining that it :Cannot cast from Object to boolean.
> 
> How can I use this boolean value?
> 
> Ben
> 
> public class ZoekDynaActionForm extends DynaActionForm {
> public ZoekDynaActionForm() {
> super();
> }
> 
> private Zoek data;
> public void setData      (Zoek data)    {this.data=data;}
> public Zoek getData() {return this.data;}
> 
> protected boolean NullOfLeeg (String str){
>  return ((str == null) || (str.length() == 0));
> }    
> public void reset(ActionMapping mapping, HttpServletRequest request)
> {
>  this.data = new Zoek();
> }    
> public ActionErrors validate(ActionMapping mapping,
> HttpServletRequest request)    {
>  ActionErrors errors = new ActionErrors();
>  if ("1".equals((String)this.get("selectie"))) {
> if
> ("".equals((String)this.get("gemeente"))&&"".equals((String)this.get("sectie
> "))&&"".equals((String)this.get("perceel"))) {
>  errors.add("Perceelkeuze", new
> ActionError("error.Perceelkeuze"));
> } else {
> if (NullOfLeeg((String)this.get("gemeente")))
> errors.add("Gemeente", new ActionError("error.gemeente.verplicht")) ;
> if (NullOfLeeg((String)this.get("sectie")))
> errors.add("Sectie", new ActionError("error.sectie.verplicht"));
> if (NullOfLeeg((String)this.get("perceel")))
> errors.add("Perceel", new ActionError("error.perceel.verplicht"));
> }
>  }
>  
>  if ("2".equals((String)this.get("selectie"))) {
> ==>          if ((boolean)this.get("volledig")) {
> errors.add("Volledige naam", new
> ActionError("error.naam.volledig"));
> } else {
> errors.add("Beginletters", new
> ActionError("error.naam.deel"));
> }
>  }
>  return (errors);
> }
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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