开发者

Trouble implementing reset button in ICEfaces 1.8.2

开发者 https://www.devze.com 2023-02-15 14:49 出处:网络
I have a form with values populated from a database. The form consists of a number of ice:inputText components with partialSubmit=\"true\", so the fields will be validated when they lose focus. The fo

I have a form with values populated from a database. The form consists of a number of ice:inputText components with partialSubmit="true", so the fields will be validated when they lose focus. The form has a save and a reset button. The reset button has immediate="true" and is just a regular ice:commandButton, i.e., not a type="reset".

Typical inputText field:

<ice:inputText id="input1" maxlength="6" size="6" value="#{client.inboxThreshold}" partialSubmit="true">
    <f:convertNumber integerOnly="true" />
    <f:validateLongRange minimum="0" />
</ice:inputText>

"Reset" button:

<ice:commandButton value="Reset" style="margin-left:5px;" actionListener="#{client.reset}" immediate="true"/>

The problem is this: When a user changes the values and clicks the reset button, the actionListener is fired which updates the backing bean values. The validation errors are removed, however, the model values don't get updated when the page is rendered.

The phase listener indicates it's going from Apply_Request开发者_Go百科_Values to Render_Response. So, I think I need to manually trigger the Update_model_values phase.

Ideas?


I didn't try it but it sounds like a typically phase problem. Iin short this means in the actionListener you set the bean values in a phase which is too early. They will be overriden by the submitedValue of the jsf component. There are two possible solutions.

First is to bind the component and set the desired value directly in the component via setSubmittedValue.

The nicer solution is the second one. You use the tag ice:setEventPhase (see taglib). With that you can force that the actionListener is called in a later phase, thus the value on the bean is not overriden by the submitted value on the jsf component.

So try to surround the ice:commandButton with <ice:setEventPhase phase="INVOKE_APPLICATION">.

PS:

The phase listener indicates it's going from Apply_Request_Values to Render_Response. So, I think I need to manually trigger the Update_model_values phase.

This comes from immediate="true". With that, ICEfaces does all phases for the component (in your case the commandButton) in the second phase (Apply_Request_Values) and goes then for the other components directly to the last phase (Render_Response). Thus the validators of the other components are not called.

I recommend reading about the phases (for example here where you also find details about immediate in section "Immediate event handling")


It is because the components will display the submitted values, not the data from your been, see http://wiki.apache.org/myfaces/ClearInputComponents for solutions.

0

精彩评论

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

关注公众号