我正在使用一个弹出窗口,其中弹出窗口位于丰富的模型面板上当我尝试创建新值并单击保存按钮并且所需的值为真时,我会收到错误消息(就像我想!!!一样),但如果此人在下次加载此弹出窗口时单击关闭(x 按钮)并调用 showmodelpanel(在更新模式下,我尝试从 JSF Bean 中获取城市值)不会写入任何值(应该有一个!!!这是我的错误)
我希望在有人关闭我的弹出窗口后,甚至认为他从验证方面得到了错误的按摩,"下次他打开弹出窗口时,将输入新值
注意:禁用的人脸是可以的,但插入值不是(奇数...
有人可以解释一下问题是什么(可以证明JSF面孔的一些东西,验证错误后如何将页面恢复到他的原始状态?
<rich:modalPanel id="DefineEntityAddress" width="400" height="300"
autosized="true">
<h:graphicImage value="/images/close.png" styleClass="hidelink"
id="DefineEntityAddressHidelink" />
<rich:componentControl for="DefineEntityAddress"
attachTo="DefineEntityAddressHidelink" event="onclick"
operation="hide">
...
<h:form>
<t:div style="display:block;height:17px;">
<rich:comboBox required="true" id="suggestionBoxCity"
value="#{DefineEntityAddressControl.chossenCity}"
suggestionValues="#{DefineEntityAddressControl.allCityNames}"
directInputSuggestions="true" required="true"
disabled="#{DefineEntityAddressControl.readOnly}"
listStyle="text-align: right;" tabindex="12">
<a4j:support event="onchange" reRender="suggestionBoxStreet"></a4j:support>
</rich:comboBox>
</t:div>
<a4j:outputPanel ajaxRendered="true">
<t:message for="suggestionBoxCity" styleClass="dyna_error"></t:message>
</a4j:outputPanel>
</a4j:region>
<a4j:commandButton id="save" value="#{l.save}"
oncomplete=" closeModalPanel();"
reRender="hidden,saveError,saveError1,#{DefineEntityAddressControl.ok ? DefineEntityAddressControl.callinglabalTorerender : l.end_date}"
disabled="#{DefineEntityAddressControl.toDelivery}"
action="#{DefineEntityAddressControl.save}"
styleClass="actionButton" />
</h:form>
</rich:modalPanel>
这是一个已知的 JSF "功能"。提交表单时,JSF 树中的组件将使用提交的值进行更新。然后验证失败,因此模型(DefineEntityAddressControl.chossenCity等)不会更新。但是提交的值仍在组件树中,JSF 在 UI 上合法地呈现该值(允许用户更正)。
解决方案是在单击"关闭"按钮时清除提交的值。
/**
* Clears all the submitted values of input components in the same form as the specified component.
* Call this method from action listener, e.g.
* In Java bean:
* {@code
* public void processCloseAction(ActionEvent e) {
* clearSubmittedValues(e.getComponent());
* }
* }
*
* At page:
* {@code
* <a4j:commandButton actionListener="#{bean.processCloseAction}"
* ajaxSingle="true"
* limitToList="true"
* oncomplete="Richfaces.hideModalPanel('#{id}')"
* value="Cancel"/>
* }
*
* @param component child of the form to be cleared
*/
public void clearSubmittedValues(UIComponent component) {
while (component != null) {
if (component instanceof UIForm || component instanceof UIAjaxRegion
|| component instanceof UIModalPanel) {
clearRegion(component);
}
component = component.getParent();
}
}
public void clearRegion(UIComponent parent) {
for (UIComponent component : parent.getChildren()) {
if (component instanceof EditableValueHolder) {
EditableValueHolder input = ((EditableValueHolder) component);
input.setSubmittedValue(null);
// The following is only needed for immediate input components
// but it won't do any harm in other situations..
input.setValue(null);
input.setLocalValueSet(false);
} else {
clearRegion(component);
}
}
}