commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marco Mistroni" <mmistr...@waersystems.com>
Subject RE: Digester simple, simple question
Date Fri, 10 Dec 2004 12:51:26 GMT
Hello,
	I believe you need to have a rule for calling a method...
Your code is creating an ArrayList, but how are you adding elements to
it?

One way to do that is to write your own class that extends arrayList.
You write ur method, let's say 'addUser', and hten you have to have
A call method rule that adds users to your class..

Something like this

<call-method-rule pattern="user-data/user" methodname="addUser"
	                paramcount="0" />


ok this is using an xml file for defining digester rules...but using the
rule in java code is the same...

regards
	marco

-----Original Message-----
From: Vinicius Caldeira Carvalho
[mailto:vinicius.carvalho@squadra.com.br] 
Sent: 10 December 2004 12:07
To: commons-user@jakarta.apache.org
Subject: Digester simple, simple question

Hi there! I'd like a little help with diggester. I tried the receipt and

it didn't work for me ...
Here's what I have:
my xml:

<user-data>
	<user name="Vinicius Carvalho" age="25"/>
	<user name="Clarissa Daguer" age="23"/>
</user-data>


the method to instantiate  the bean:

clazz = org.vinicius.User.class;

File input = new File(path);
		Digester digester = new Digester();
		digester.setValidating(false);
	
digester.addObjectCreate("user-data","java.util.ArrayList");
	
digester.addObjectCreate("user-data/user",clazz.getName());
		digester.addSetProperties("user-data/user");		
	
digester.addSetNext("user-data/user","add",clazz.getName());
		Object obj = null;
		try {
			 obj = digester.parse(input);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj;


The bean is a simple userBean with name and age properties.
What I'd like to do is to have an arrayList of users returned to me.

What am I doing wrong



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


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


Mime
View raw message