English 中文(简体)
验证出错后, Ajax 请求后从UI 部件而不是 Beans 获得数值
原标题:After validation error subsequent ajax requests get values from UI Components and not from Beans

在我基于JSF2的申请表中,我有一个表格,包括(除UI的其他组成部分外)一些复选框。

On the checkboxes I have registered ajax requests that fire when they are checked. The ajax requests will actually just update the value of another checkbox in the backing bean. As a result the other checkbox will also be checked (when it gets re-rendered - as it will take the updated value from the backing bean in the render response phase).

This works fine until the whole form gets submitted and validation errors occur. Then the ajax requests still work and change the value on the backing bean but in the phase of re-rendering the updated checkbox the value for it is not taken from the backing bean but from a cached value that is taken from a ComponentStateHelper class.

据我所知,这被用于JSF 2的新特点,只储存对树组成部分的部分改动。

我不明白的是:这与验证阶段有什么关系?为什么在验证发现错误时我的复选框的 StateHelper 类中有一个缓存值?

最佳回答

这个问题在< a href=> https://stackoverflow.com/ questions 66422/how-can-i-populate-a-text-field-using-primefaces-ajax-fter-validation-errors-oc/684800#6845800>> > 的答案 中是一个已知的问题,并对此作了深入解释。在简而言之,问题之所以产生,是因为由 lt;f:ajax making> 提供的无效的组件不是由 ;f:ajax 执行 & gt; 执行的,但与最初提交的值一样, 仍然处于无效状态。 当 JSF 提供输入部分时, JSF 将首先检查所提交的值是否 < null , 然后再显示它, 否则将显示模型值。 您基本上需要重新设定要完成的输入组件的提交值, 而不是由 ajax 执行。

为此,您可以使用 < a href=""http://docs.oracle.com/javaee/6/api/javax/face/event/ActionListener.html" rel="Nofollow noreferr"\\code > ActionListener ,而“em>基本上 这样做:

UIViewRoot viewRoot = context.getViewRoot();
PartialViewContext partialViewContext = facesContext.getPartialViewContext();
Set<EditableValueHolder> inputs = new HashSet<EditableValueHolder>();

// First find all to be rendered inputs and add them to the set.
findAndAddEditableValueHolders(partialViewContext.getRenderIds(), inputs);

// Then find all executed inputs and remove them from the set.
findAndRemoveEditableValueHolders(partialViewContext.getExecuteIds(), inputs);

// The set now contains inputs which are to be rendered, but which are not been executed. Reset them.
for (EditableValueHolder input : inputs) {
    input.resetValue();
}

这已被报告为' rel=“不随从不退”/JSF 问题1060 < a>。 在“http://omnifaces.org” rel=“nofollown noreferrrer” > > > >OmniFaces 图书馆 < arefref=>.comml=“noceptnrenrenrereferral' refrere>(源代码

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签