Best practices for combo boxes

Discussions

General J2EE: Best practices for combo boxes

  1. Best practices for combo boxes (7 messages)

    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

    Threaded Messages (7)

  2. Best practices for combo boxes[ Go to top ]

    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.
  3. Cool....[ Go to top ]

    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.
  4. Re: Best practices for combo boxes[ Go to top ]

    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.
    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
  5. Best practices for combo boxes[ Go to top ]

    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
  6. Best practices for combo boxes[ Go to top ]

    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.
  7. Great idea...[ Go to top ]

    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.
  8. Great idea...[ Go to top ]

    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;
        }
    }