views:

448

answers:

2

I'm trying to reset some input text fields, inside of a data table, using a cancel button. The issue I'm having is that, if I attempt to cancel it, but there are validation errors, it does not allow me to do so because it does validation first, finds and error, and outputs the error before it can rerender itself.

The obvious solution is to set "immediate=true" on the button. This gets rid of the issue and allows me to cancel without validation BUT the fields themselves are not set to their original values. This is because the components themselves never reget the data from the backing beans BECAUSE of immediate is set to true.

This is very well explained in this article: http://wiki.apache.org/myfaces/ClearInputComponents

The article presents many solutions, but none of them work for me.

  • I have to stay on the same page, so changing views is not an option.
  • I can't reset the values of ALL input fields on the page because I only want the 'row' that I cancel to be reset
  • I can't seem to bind components to any of the input fields because, since they are in a datable, the "binding" attribute of the input field itself cannot reference a 'var' variable. For example, the following "binding" attribute is illegal and gives me an error:

    <ice:dataTable id="poolSharesTbl" var="node" value="#{poolSharesManager.nodeModel}" ... <ice:column> <ice:inputText binding="#{node.inputTextBinding}" ...

This may have to do with 'var' only being request-scope.

Anyway, does anyone have any ideas on how to get this working?

+3  A: 

It's a pain to do so with JSF. You have very little control over the validation. Your best bet is using JavaScript to reset the values. It's done in only a few lines (or an oneliner with jQuery) instead of tens up to with hundred which you would do to workaround this the jsfish way.

BalusC
I don't think you can reset the values to the original ones, using javascript, if you, for example, each inputText field has partialSubmit="true", as I am doing. A javascript reset would probably just reset them to the last bound value...not just their original ones.You'd probably have to have hidden fields to coincide with each input field, containing the original value, then copying the hidden value into the input field on reset. Right?
wfsaxton
Then you need to elaborate more what you mean with "reset".
BalusC
A: 

In any event, I ended up using a workaround that only required about 50 lines of code, more or less, to manually do the validation and converting the inputtext values (which are Strings be default) to Integers. I had bad experiences mixing javascript with JSF (Woodstock library) before so I'm scared of introducing it into the environment again ;)

wfsaxton
Oh, Woodstock makes JSF more a pain, indeed. Good luck.
BalusC