| Author |
Can I use array of Beans?
|
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi everybody, I am Chaitanya, I have a link which when clicked requests list of users present. There is a model which selects the list of users with their names.
If it is one single user all his information is retrieved and dumped in to the Bean. Now I am retrieving list of users with their names only. Not the entire details.
I have setter and getter methods in Bean. So if I retrieve 10 user names, then I should have a array of 10 Beans. Can I do like this?
And this Bean consists of 25 setter and getter methods. Here I am using only set user name property. The rest of the setter and getter methods are useless.
Can I go with Beans or simply create an array? If I should go with Beans, then, can I use the previous Bean which consists of 25 setter and getter properties. Or shall I create another Bean which exactly consists the name property?
Thank you all in advance. Have a good day.
|
Love all, trust a few, do wrong to none.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56231
|
|
|
Of course -- why not? Are you running into any specific difficulty?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Bear Bibeault wrote:Of course -- why not? Are you running into any specific difficulty?
No Mr. Bear, I don't have any specific difficulty. I just don't know that should I create array of Beans or go for an array. Thats it. Thank you sir.
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi Mr. Bear, Array of beans is not working, it is reporting a null pointer exception.
Can you please tell me where is the mistake? Thank you in advance.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56231
|
|
|
You need to check your basic Java logic.
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Bear Bibeault wrote:You need to check your basic Java logic.
Everything is fine, it is working with String Array, not with Bean Array. I just replaced the Bean class with String. It worked fine. Coming to Beans it is not working.
|
 |
Hebert Coelho
Ranch Hand
Joined: Jul 14, 2010
Posts: 754
|
|
Hello.
What's the error message?
|
[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
|
It is giving a null pointer exception Mr. Herbert.
|
 |
Hebert Coelho
Ranch Hand
Joined: Jul 14, 2010
Posts: 754
|
|
|
Wich line?
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hebert Coelho wrote:Wich line?
The error lies in the while loop. I also checked whether there are any records in the faculty table. There are 3 records. So the Bean is initialized to array of size 3.
|
 |
Hebert Coelho
Ranch Hand
Joined: Jul 14, 2010
Posts: 754
|
|
I know this is not the answer you want to hear but, trust me, is the best answer for you...
Bear Bibeault wrote:You need to check your basic Java logic.
When you find it, you won't never fell for it again. [=
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
|
I did not understand what you said
|
 |
Nilesh Miskin
Ranch Hand
Joined: Jun 17, 2010
Posts: 44
|
|
@Chaitanya
The way you are creating an array of beans is wrong. Please see this example for a hint.
|
Nilesh Miskin
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Also, the Arrays tutorial.
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: Can I use array of Beans?
|
|
|