我正在使用弹出窗口,其中弹出窗口位于丰富的模型面板上 当我尝试创建新值并单击保存按钮并且没有值时,所需的是真的我得到错误的消息(就像我想!!!!)但如果这个人点击关闭(x按钮)下次这个pop被加载并且正在调用showmodelpanel(在更新模式下,我尝试从jsf bean获取city值)没有写入值(应该有一个!!!!这是我的错误)
我希望在有人关闭我的弹出窗口后,即使他认为他从验证方面得到了错误的按摩'下次他打开弹出窗口时会输入新的值
注意:禁用的面部正常,但插入的值不是(奇数....)
有人可以解释什么是问题(可证明是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>
答案 0 :(得分:1)
这是一个已知的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);
}
}
}