Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different(Efficient) way of handling big file of getters and setters(javaBean) in java

 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody

Ist stage : i have a form(jsp) having big table say(30*20) of fields , where i am asking user to enter those fields.

II nd Stage : i am fetching those data in a servlet and setting those data through javabean function in bean object.

Problem: The problem is to set these fields i need to call every bean function one by one .Obviously it will take very long.
and if table is larger it will take even more.

So is there any efficient way of using bean function or how to create and use bean functions so that we can get and set values of field effficiently .



my form is something like this(say)..

Country Population language Primeminister president ....... ......... .............

India

USA

UK

Russia

China

....


....


......


the form order could vary in future
means i may increase or decrease countries .

Currently i am having only one java bean class

where i have variables like indiaPopulation, indiaLanguage ....
and functions like int getIndiaPopulation() , String getIndiaLanguage(), void setIndiaPopulation(int indiaPopulation) ,
void setIndiaLanguage(String indiaLanguage ) .................

please help

ragards
thanks
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use struts.... and attach an ActionForm to this form in JSP. All the data will be automatically populated.
 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any way without struts.

and it's not only a question of population of datas but also of after fetching how easily i can set the data(fields) and get those values whenever required through bean
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get rid of country-specific getters and add a getter getName(), then collect the data in a List<Country> and use JSTL c:forEach to iterate over it and display the table.
 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can you please show by an example...as i am new to it.
i also need to store the data in a database .....and later fetch from the database.....so will simply putting the values in arayy and displaying in tables ,solve my purpose.

 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i also need to set the values i am fetching from screen as setters...how can whole thing happen.
can you show bay an example.
regards
thanks
 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
what is the way to define getters and setters for a table values.
can any one suugest an answer through an example.
since the table is very big ..what is the efficient way...say may be using Array or an Array list or something else?/
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a bean class which represents one row (one Country).
Then create/collect multiple instances of that bean together in a List.
In JSP you can use c:forEach to iterate over that List.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic