1

I'm using Primefaces 3.5.2, Mojara 2.1.2. I have a main xhtml page and a dialog in this page. Below is a simple example

<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>   

Managed Bean:

@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 (..) { ... }

}

If I open the dialog, write in input field (input1) something wrong, e.g. text instead of number, and click "ok", then the input will be invalid and marked as red. I close the dialog with cancel or close button. If I reopen the dialog the input field remains marked as red. I don't want this behaviour.

Another problem: in invalidated state "select"-Component from Primefaces changes often the size. If I replace p:selectOneMenu with h:selectOneMenu then the component has the right size.

My question is how you can change the state of JSF/Primefaces so that the JSF will be in "validate" state after you reopen the dialog and JSF will not show highlighting.

I have tried to change the component state with setValid(true) for all components in "myBean.cancel" it does not help however. Similar as in this question How to mark other components invalid in a custom multi-field validator

Update

Thank you, the problem with red borders is disappeared. But I have another one very similar problem. see: p:SelectOneMenue changes size in Primefaces/JSF if Converter/Validator error occurs

Community
  • 1
  • 1
Tony
  • 2,266
  • 4
  • 33
  • 54

1 Answers1

5

For resetting input fields consider using Omnifaces. Omnifaces provides a ResetInputAjaxActionListener for this. See here for more: http://showcase.omnifaces.org/eventlisteners/ResetInputAjaxActionListener.

Update 1

Since PrimeFaces 3.4 you can also use <p:resetInput> instead of Omnifaces ResetInputAjaxActionListener. See here: http://www.primefaces.org/showcase/ui/resetInput.jsf

Update 2

And since JSF 2.2 you can also use <f:ajax ... resetValues="true"/> or <f:resetValues render="...">.

fischermatte
  • 3,327
  • 4
  • 42
  • 52