We have a complex web form (we use GWT/GXT stack) with lots of input elements of different types (text fields, selects, checkboxes, buttons), and behavior of these elements depends on each other.

Now it means, to set form element state correctly, it's necessary to know what happened to it (user input occurred or an event came from server) and state of other elements of that form.

So, the question is what best practices to maintain code for such a complex web form in clean and comprehensible state? Now it seems that ideal solution would employ some form of declarative DSL to describe said behavior.

Initial brain storming produced following kind of Java DSL (this is just to give an idea what I mean, no any real DSL exists right now):

private Event whenStopOrderChanged;
private Predicate parentPriceValid;
private Command calculateStopPrice;

public void initRules() {

So, could you please share your ideas/experience solving such kind of task?

  • When you say "behavior of these elements depends on each other" it makes me want to enable/disable input controls based on user action. E.g. don't even let the user do whatever it is that causes StopOrderChanged until there is a valid parentPrice. I.e. OnParentPriceChanged { if parentPriceValid { StopOrder.enabled = True (I hope that that makes some sort of sense – Mawg Jan 27 '15 at 14:48

Those form fields are part of the presentation layer. You should have a view model, basically a model for that presentation. That viewModel has to have the entire state for that form fields. The state should be: their value, their enabled/disabled, etc...

So, when you present those fields in the screen you'll have to load the state from your viewModel. And after user interacts, there will a new state for these fields: you will sync the viewmodel with the new state.

What for? Because then if you open a new tab in the web browser you'll see an updated scene with your last changes.

Where does the viewModel live? In the session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.