wsaxton
wsaxton

Reputation: 1082

Problems with Clearing InputText in a JSF Datatable

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.

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

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

Upvotes: 4

Views: 2328

Answers (2)

wsaxton
wsaxton

Reputation: 1082

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 ;)

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

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.

Upvotes: 4

Related Questions