开发者

Problems with Clearing InputText in a JSF Datatable

开发者 https://www.devze.com 2022-12-20 19:21 出处:网络
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

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" valu开发者_开发百科e="#{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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号