Dear all,
I have been developing with J2EE for a couple of years now, and I still am foggy on how to elegantly build internationalized combo boxes (select boxes).
Our database has a language field in which we query to retrieve the data from, and we use that data to populate comboboxes. (Provinces in english, and provinces in french perhaps)
What we currently do, is when a user logs in, we capture their Locale, and call our SQL classes to build session objects that are retreived when a user accesses a JSP page.
The Struts SELECT tag uses these session objects and retrieves the Collection of LabeValueBeans to populate the combo boxes. (ex. <html:select>....<html:options collection="provinces" ...etc>
The problem with this approach is that there are copies of duplicate session objects for each user signed on.
I would like to build one JSP for ALL languages. Is there perhaps a better way to do this? Throw all tables in the application scope perhaps and pass the language?
Any posts would be great. Thanx
-
Best practices for combo boxes (7 messages)
- Posted by: Ryan Allaby
- Posted on: March 18 2005 11:51 EST
Threaded Messages (7)
- Best practices for combo boxes by Matthew Wilson on March 18 2005 14:26 EST
- Cool.... by Ryan Allaby on March 21 2005 07:49 EST
- Re: Best practices for combo boxes by divya chamarti on September 07 2006 03:08 EDT
- Best practices for combo boxes by olivier martin on March 21 2005 08:42 EST
- Best practices for combo boxes by Rakesh Malpani on March 22 2005 16:32 EST
- Great idea... by Ryan Allaby on March 24 2005 14:21 EST
- Great idea... by Rakesh Malpani on March 24 2005 05:12 EST
- Great idea... by Ryan Allaby on March 24 2005 14:21 EST
-
Best practices for combo boxes[ Go to top ]
- Posted by: Matthew Wilson
- Posted on: March 18 2005 14:26 EST
- in response to Ryan Allaby
I have used resource bundles, combined with a property file to define all the valid choices.
# This file defines a pojo.method as the key,
# and the valid choises as the values.
ListKeys.configuration
net.mlw.MyObject.myProperty=0|1|2|3|4|5|6|7
net.mlw.MyObject.myOtherProperty=0|1|2
#This is a resource bundle that is references by the
#custom tag that generates the combo box.
ListValues.en_properties
net.mlw.MyObject.myProperty(0)=N/A
net.mlw.MyObject.myProperty(1)=Choise 1
net.mlw.MyObject.myProperty(2)=Choise 2
net.mlw.MyObject.myProperty(3)=Choise 3
net.mlw.MyObject.myProperty(4)=Choise 4
net.mlw.MyObject.myProperty(5)=Choise 5
net.mlw.MyObject.myProperty(6)=Choise 6
net.mlw.MyObject.myProperty(7)=Choise 7
net.mlw.MyObject.myOtherProperty(0)=N/A
net.mlw.MyObject.myOtherProperty(1)=Yes
net.mlw.MyObject.myOtherProperty(2)=No
This has worked real well in the past. You could skip the ListKeys.configuration file and put htis in teh database, but it is simplier to have that in a property file. -
Cool....[ Go to top ]
- Posted by: Ryan Allaby
- Posted on: March 21 2005 07:49 EST
- in response to Matthew Wilson
I've tried that approach before as well, and yes it works really well.
The only problem I have with that method is how do you keep your properties files updated if the data needs to be maintained on the database level.
I understand that with province names, this information is not updated all the time. However, other informations require a database to drive the system.
I would be convinced that property files are the best approach if this updating issue was simple to resolve. -
Re: Best practices for combo boxes[ Go to top ]
- Posted by: divya chamarti
- Posted on: September 07 2006 03:08 EDT
- in response to Matthew Wilson
I have used resource bundles, combined with a property file to define all the valid choices.
Hello Metthew can you tell me what are the other configuration which we have to do to populate the combo box for getting the value from resource file????????? i mean what we need to add in struts-config.xml file and what the code need to add in jsp page(i.e. form) order to retrive the value from resource file? and also what is here net?,mlw?,MyObject?,myOtherProperty? listed above if u can provide me sample example then it will be better for me to understand the concept please help me thanks in advance
# This file defines a pojo.method as the key,
# and the valid choises as the values.
ListKeys.configuration
net.mlw.MyObject.myProperty=0|1|2|3|4|5|6|7
net.mlw.MyObject.myOtherProperty=0|1|2
#This is a resource bundle that is references by the
#custom tag that generates the combo box.
ListValues.en_properties
net.mlw.MyObject.myProperty(0)=N/A
net.mlw.MyObject.myProperty(1)=Choise 1
net.mlw.MyObject.myProperty(2)=Choise 2
net.mlw.MyObject.myProperty(3)=Choise 3
net.mlw.MyObject.myProperty(4)=Choise 4
net.mlw.MyObject.myProperty(5)=Choise 5
net.mlw.MyObject.myProperty(6)=Choise 6
net.mlw.MyObject.myProperty(7)=Choise 7
net.mlw.MyObject.myOtherProperty(0)=N/A
net.mlw.MyObject.myOtherProperty(1)=Yes
net.mlw.MyObject.myOtherProperty(2)=No
This has worked real well in the past. You could skip the ListKeys.configuration file and put htis in teh database, but it is simplier to have that in a property file. -
Best practices for combo boxes[ Go to top ]
- Posted by: olivier martin
- Posted on: March 21 2005 08:42 EST
- in response to Ryan Allaby
Hi ryan,
you can use the SweetDEV framework. You will find combo boxes and many otrhers tags.
It is free. You can download it at www.ideotechnologies.com
good luck
olivier -
Best practices for combo boxes[ Go to top ]
- Posted by: Rakesh Malpani
- Posted on: March 22 2005 16:32 EST
- in response to Ryan Allaby
Hi,
Instead of using a sql directly, why don't you run it through a helper class, which can cache and update information, and hence you still work the same way, just that instead of running a query, you invoke a function over the caching framework/class, and it, depending on various criteria, provides back an array/resultset.
That way you avoid multiple copies/memory overhead problem, and also increase the performance by not hitting the database every time.
And even best, if you are expecting the drop down values to be more or less static, then this would be perfectly good, as opposed to drop down for which the data might be changing contineously in the back end.
Hope it helps,
Rakesh. -
Great idea...[ Go to top ]
- Posted by: Ryan Allaby
- Posted on: March 24 2005 14:21 EST
- in response to Rakesh Malpani
Rakesh,
That sounds like the best idea.. Would you have an example of such a class that I would be able to take a look at?
Thank-you kindly,
Ryan Allaby. -
Great idea...[ Go to top ]
- Posted by: Rakesh Malpani
- Posted on: March 24 2005 17:12 EST
- in response to Ryan Allaby
its a slightly different example.. but you can modify the getXYZfee function to what ever you want..
Hope it helps..
Rakesh.
public class FeeHelper
{
public static ResultSet carFeeRS = null;
public static double xyzFee = -1.0;
int feeColId = 0;
public static void cacheCarFeeRS() throws SQLException
{
if(carFeeRS == null)
{
try
{
Connection efmsConn = DBHelper.getNYSEEFMSConn();
PreparedStatement tmpStmp = efmsConn.prepareStatement(carFeeSql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
carFeeRS = tmpStmp.executeQuery();
}
catch(SQLException e)
{
Logger.getInstance().error(e, e.getMessage());
throw e;
}
}
}
public static double getXyzFee()
{
if(xyzFee != -1.0)
{
return xyzFee;
}
try
{
if(carFeeRS == null)
{
cacheCarFeeRS();
}
//int numRows = DBHelper.getNumRecords(carFeeRS);
carFeeRS.beforeFirst();
while(carFeeRS.next())
{
if(carFeeRS.getInt(carSeqColId) == 2)
{
xyzFee = carFeeRS.getDouble(feeColId);
Logger.getInstance().debug("Setting XYZ Fee = " + xyzFee);
}
}
}
catch(Exception e)
{
Logger.getInstance().error(e, e.getMessage());
xyzFee = -1.0;
}
return xyzFee;
}
}