UI Builder

Hi,I’ve got a UI, which ought to look very different, depending on an application state. To handle this, I’d like to have an interface like

public interface UIBuilder { UI getUI(); } and configure that in web.xml. My UIBuilder would look like

public UI getUI() { if (isInExceptionalState()) { return new ExceptionalUI(); } else { return new DefaultUI(); } Otherwise I’d have to check for isExceptionalState() in the UI class a lot.

Alternatively, I might replace the UI upon state change with something like


Is something along these lines possible? Or do you have other suggestions how to handle my situation?



This sounds like a UIProvider which allows you to select which UI to use based on parameters, browsers used etc.

If you want to change this on the fly, it would be better not to select/swap the UI class (actually you can’t do that without a page reload due to the way UI is defined) but instead switch the contents of your UI to MyExceptionalContent or DefaultContent.

Thanks, Artur, that seems to be exactly what I’m looking for. The UIProvider returns a class, and not an instance, but that should be fine for my purposes.