如何摆脱 JSF/Primefaces 中无效组件的突出显示

Ton*_*ony 1 validation converter primefaces jsf-2

我使用的是 Primefaces 3.5.2、Mojara 2.1.2。我有一个主 xhtml 页面和此页面中的一个对话框。下面是一个简单的例子

<h:form>
   <p:commandButton id="btn1" oncomplete="dlg.show()" update="dlg" process="@form"/>
</h:form>

   <p:dialog id="dlg" widgetVar="dlg">
      <h:form>
         <p:tabView id="tabview" activeIndex="..always 0 ...">
           <p:tab id="tab1">
             <p:panelGrid>
               <p:inputText id="input1" value="#{myBean.integer}"/>

             p:selectOneMenue is rendered wrong, if the dialog is reopened.
               <p:selectOneMenu id="select" value="#{myBean.listVal}" filter="true" style="width:100%">
                 <p:selectItems value="#{myBean.list}" />
               </p:selectOneMenu>
               <p:commandButton action="#{myBean.ok}" value="ok" oncomplete="..." update="dlg" process="@form"/>
               <p:commandButton action="#{myBean.cancel}" value="cancel"  update="dlg" process="@form"oncomplete="dlg.hide()"/>
             <p:panelGrid>
           </p:tab>
           <p:tab id="tab2">
            ...
           </p:tab>
         </p:tabView>
      </h:form>
   </p:dialog>   
Run Code Online (Sandbox Code Playgroud)

托管豆:

@ManagedBean
@SessionScoped
class MyBean {
   Integer integer;
   String listVal;

   public Integer getInteger() { ... }
   public void setInteger (Integer i) { ... }
   public void ok() { ... }
   public void cancel() { ... }

   public List<SelectItem> getList() { ... }
   public getListVal () { ... } 
   public setListVal (..) { ... }

}
Run Code Online (Sandbox Code Playgroud)

如果我打开对话框,在输入字段 (input1) 中写一些错误,例如文本而不是数字,然后单击“确定”,则输入将无效并标记为红色。我用取消或关闭按钮关闭对话框。如果我重新打开对话框,输入字段仍标记为红色。我不想要这种行为。

另一个问题:在无效状态“select”-Component from Primefaces 经常改变大小。如果我用 h:selectOneMenu 替换 p:selectOneMenu ,则组件的大小合适。

我的问题是如何更改 JSF/Primefaces 的状态,以便在您重新打开对话框后 JSF 将处于“验证”状态并且 JSF 不会显示突出显示。

我尝试使用 setValid(true) 为“myBean.cancel”中的所有组件更改组件状态,但是它没有帮助。类似于这个问题 如何在自定义多字段验证器中标记其他组件无效

更新

谢谢,红色边框的问题消失了。但我还有另一个非常相似的问题。请参阅:如果发生转换器/验证器错误,p:SelectOneMenue 会更改 Primefaces/JSF 中的大小

fis*_*tte 5

要重置输入字段,请考虑使用 Omnifaces。Omnifaces 为此提供了一个 ResetInputAjaxActionListener。有关更多信息,请参见此处:http : //showcase.omnifaces.org/eventlisteners/ResetInputAjaxActionListener

更新 1

从 PrimeFaces 3.4 开始,您还可以使用<p:resetInput>Omnifaces 代替ResetInputAjaxActionListener。见这里:http : //www.primefaces.org/showcase/ui/resetInput.jsf

更新 2

从 JSF 2.2 开始,您还可以使用<f:ajax ... resetValues="true"/><f:resetValues render="...">