Nik
Nik

Reputation: 201

UI customization in java web application

In my web application there is a need to customize the UI. For example, hide menu(s) or menu section, hide some columns or buttons etc.

What is the best practice to follow in this situation? The application should be able to restore the settings for a user, if he has modified it. the application does not have any database. Is XML the way to go? I need a good reference example.

-Nik.

Upvotes: 0

Views: 475

Answers (2)

OpenSauce
OpenSauce

Reputation: 8623

The java.util.prefs package was designed for this. The Preferences class has import and export methods which work with XML.

Upvotes: 0

ccoakley
ccoakley

Reputation: 3255

The application does not have any database

Do you store any state? If so, where and how? If the answer is "in xml on the filesystem," then I suppose in xml on the filesystem is a fine place to store your preferences.

Are the user's choices persistent across sessions? Are there sessions? If there aren't, or there's no need for persistence, then storing them as parameters you pass around might be fine.

As far as a reference, I'm not sure. What is your web app using? Is it just a java server you wrote yourself? A collection of jsp pages running in tomcat? A struts/spring/whatever application? If you just want a trivial example, check out a xerces tutorial. Perhaps the xml document looks like this, with a unique key for the user determining which file to read from the filesystem.

user_preferences_1341342134.xml

<preferences>
  <pref name="show_graphs" value="false"/>
  <pref name="background_color" value="#ffffff"/>
  <pref name="rounded_corners" value="true"/>
</preferences>

Or maybe you want a specific element for each preference type:

<preferences>
  <show_graphs>false</show_graphs>
  <background_color>#ffffff</background_color>
  <rounded_corners>true</rounded_corners>
</preferences>

Anyway, if you have a default_preferences.xml, you can use that to restore things.

Upvotes: 1

Related Questions