2

I want to reset my JSF form. I've implemented an Action method that resets all properties in the backing bean.

When I return a String that forwards to the same page again, all form entries are reset. Input text boxes as well as comboboxes.

But when I return null only the input text boxes are reset, not the comboboxes.

I don't understand this behavior. Both ways call the same method, both forward to the same page.

gebuh
  • 797
  • 14
  • 40

1 Answers1

5

Returning an outcome from an action method causes a new instance of the view (with a new component tree) to be constructed. If you return null instead, the existing view instance (the existing component tree) is reused.

Components in JSF are allowed to be stateful. For instance, JSF does not update the model (the backingbean) if validation fails, but still rerenders the invalid data the user entered. This is implemented by keeping the invalid data in the component.

meriton
  • 68,356
  • 14
  • 108
  • 175