0

I'm trying to use primefaces selectManyCheckBox with ajax and converter, but the ajax not fired. If I'm didn't use converter, the ajax can fired. Is there something wrong with my converter?

<div class="form-group">
    <p:outputLabel value="Atur Grade Pinjaman" for="gradePinjaman"/>        
    <p:selectManyCheckbox id="gradePinjaman" value="#{autoInvestController.param.grades}" converter="companyGradeConverter">
        <f:selectItems value="#{autoInvestController.grades}" var="grade" itemLabel="#{grade.id}" itemValue="#{grade}"/>                        
        <p:ajax update="selectAll estimation" listener="#{autoInvestController.valueChange}"/>
    </p:selectManyCheckbox>                
    <p:message for="gradePinjaman"/>
</div>

Here is my backing bean code

public void valueChange() {     
    if (param.getGrades() != null && !param.getGrades().isEmpty()) {
        checkAll = param.getGrades().size() == grades.size();
        calculateCollectEstimation();
    }
}

Here is my converter

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {        
    if (Strings.isNullOrEmpty(value)) {
        return null;
    } else {
        try {
            PlatformService platformService = (PlatformService) CDI.current().select(PlatformService.class).get();
            Map<String, Object> param = new HashMap<>();
            param.put("id", value);
            CompanyGradeResponse companyGrade = platformService.getCompanyGrade(param).get(0);                
            return companyGrade;
        } catch (EndpointException e) {
            LOG.error(e.getMessage(), e);
            return null;
        }            
    }
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {        
    if (value != null) {
        return ((CompanyGradeResponse) value).getId();
    } else {
        return null;
    }
}

I think my converter work well, but why the ajax won't fired when i check the checkbox?

Thanks

berry
  • 97
  • 1
  • 13
  • 1
    With 99% certainty, your problem is solved by one of the bullets mentioned in https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value. And did you try with a plain jsf `h:selectManyCheckbox`? – Kukeltje Mar 05 '19 at 09:27
  • 1
    _"I think my converter work well, "_ You can always try without ajax... do make **sure** your converter works... – Kukeltje Mar 05 '19 at 09:32
  • No, I didn't try with plain jsf...Ok, i will try without ajax to make sure my converter is working well..As soon as i will update the result – berry Mar 05 '19 at 09:50
  • Btw what do u mean by "You can always try without ajax" to make sure the converter works? method "getAsObject" only called when I use ajax right? I already debug my application and "getAsObject" return the right object – berry Mar 05 '19 at 10:14
  • thank you for your clue...It turn out JSF will perform equal operation between the converter and data on page...The equal operation failed so ajax not fired. So I override the equal method then the ajax success triggered...Thank you very much – berry Mar 05 '19 at 11:07
  • See... This is debugging... creating a [mcve]... **always** do this... Simplify, remove code etc... – Kukeltje Mar 05 '19 at 11:09
  • But an 'equal' operation between converter and data on the page? Where? What was your error then? – Kukeltje Mar 05 '19 at 11:17
  • first on the p:ajax i update the p:message element then error message show says "validation failed". It looks like when i click the check box, the getAsObject will triggered then equal operation perform between return from getAsObject with object from the check box. I add override method equal on the CompanyGradeResponse object – berry Mar 06 '19 at 03:03
  • @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final CompanyGradeResponse other = (CompanyGradeResponse) obj; return Objects.equals(this.id, other.id); } – berry Mar 06 '19 at 03:03
  • If i didn't override equals method, the return always false – berry Mar 06 '19 at 03:04

0 Answers0