Skip to main content

How to get all component in a form

2 replies [Last post]
ousys
Offline
Joined: 2008-05-14

Hello , several days ago, I asked some questions here, and got answered, thanks very much!
now I have no idea about how to get all components in a form such as all textfields+comboBox, no matter whatever component , I just wanna get all the component property and send it to server side,
as I do one thing which sounds a bit stupid:

<br />
<?xml version="1.0"></p>
<p>

So I just do parse the xml file, and do such things which sounds really not clever, but now I have no time to modify it .

<br />
Button button;<br />
TextField textfield;<br />
Component com;<br />
while(NOT REACH THE END OF THE XML FILE){<br />
if(tag.equals("button")){<br />
button=new Button();<br />
com=button;<br />
}<br />
else if(tag.equals("textfield"){<br />
textfield=new TextField();<br />
com=textfield;<br />
}<br />
...<br />
form.addComponent(com);<br />
}</p>
<p>

So it is difficult to differentiate each component , I think if the component is displayed, then I could get it , is it? is there any method could help get all component in the form?
because I need get all the data and send them to server, by the way I do one thing:

System.out.println("Component Count"+form.getComponentCount());

which give me result of
Component Count3

However, I am sure there are at least 5 components, hah!
anyone can give me an idea?
thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nafs
Offline
Joined: 2008-06-10

1)
These questions are not LWUIT related. I think this place needs stricter moderation...

2)
Anyway, I am a little unsure of what you are trying to do. But it seems you want to keep track of every Component that is added in your Form. Why don't you just do that manually using a Vector of Components.
while(NOT REACH END OF XML FILE)
{
...
form.addComponent(com)
vector.addElement(com)
}

Keep in mind that you have a Vector of Component objects. Therefore in order to determine what type of Component you'll need something like this..

Component com = (Component)vector.elementAt(whatever);
if(com instanceof Textfield)
{
// do stuff
}
else if (com instanceof List)
{
//do stuff
}
else if (com instanceof Button)
etc..

ousys
Offline
Joined: 2008-05-14

Sorry and thank you