p:表单验证后自动完成值丢失

时间:2019-01-09 07:21:04

标签: jsf primefaces

我使用PrimeFaces p:autoComplete组件。表单验证后,它无法正常工作。例如,如果我将表单中的任何其他组件留空,然后从验证中获取消息,则autoComplete会丢失值。并且转换器尝试转换选定的对象,结果autoComplete返回null值。

    public class OrganizationConverter implements Converter {

        public Object getAsObject(FacesContext fc, UIComponent uic, String value) {

            Organization organization = null;

            if(value != null && value.trim().length() >0) {
                 try{
                     try {
                         organization = DAO.OrganizationDAO.findOrganizationByCode(value);}
                     catch (IOException ex) {
                         Logger.getLogger(OrganizationConverter.class.getName()).log(Level.SEVERE, null, ex);}
                    }
                 catch(NumberFormatException e) {
                    throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
                }}

            System.out.println("conwerter: value"+value+ "object"+organization);

            return organization;
    }

   public String getAsString(FacesContext fc, UIComponent uic, Object object) {

            if(object != null) {
                return String.valueOf((object));
            }
            else {
                return null;
            }
        }   
    }

<< / p>

<p:autoComplete id="organizationAutoComlete" minQueryLength="2" forceSelection="true" selectLimit="1" autocomplete="" style="width:338px;" value="#{addTrainingBean.re0.training.organization}" converter="organizationConverter" completeMethod="#{addTrainingBean.completeOrganization}" immediate="false" var="theme" itemValue="#{theme.code}" itemLabel="#{theme.name}"  scrollHeight="400" dropdown="true" dropdownMode="current" required="true" requiredMessage="Uzupełnij pole Organizator">
       <p:column headerText="Kod:">
          <h:outputText value="#{theme.code}" />
       </p:column>
  </p:autoComplete> 

0 个答案:

没有答案