[Logo] Mentawai Recipes
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Moderation Log] Moderation Log   [Register] Register / 
[Login] Login 
Global Lists  XML
Forum Index » Official Recipes
Author Message

Joined: 10/01/2008 08:20:15
Messages: 39

A global list is a list that does not change very often and is the same for all users in a web application.

Examples: list of genders, list of cities, list of age ranges, list of browsers, list of interests, list of month, etc.

A list can come from a file or from a database. Although not very recommended, you can also hardcode the list inside the your ApplicationManager.java.

Coming from a file in the default directory /lists: (genders_en_US.i18n)

That's it! Now you can use the mtw:select tag to display your list like this:

Or you can access your list through code:

When using internationalization, you will have a list for each locale (language). Let's add another file to the /lists directory: (genders_pt_BR.i18n)

The mtw:select tag will automatically pick the right list for you, depending on the user locale. Using code you could do this now:

When using the mtw:out tag, you can just pass the list to print a value from the list:

Assuming that user.getGender() returns an id from the list, Mentawai will pick up the element from the "genders" list from the user locale.

You can also load a list from the database in the ApplicationManager, for example:

Now if you don't have the locale column in your database and you want to load a single non-localized ListData, then you can just remove the locale column name from the constructor:

If you are lazy or if your list is so small that you don't care much, you can hardcode the list items inside the ApplicationManager:

If your list is localized, you can use the the LocalizedListData:
Forum Index » Official Recipes
Go to:   
Powered by JForum 2.1.8 © JForum Team