0

I’m trying to update a part of my page using the following command:

<p:commandButton id="deleteDirectPaymentLine-#{counter.index}"
     icon="fa fa-close Fs16 white"
     action="#{step.deleteDirectPaymentLine(directPaymentLine)}"
     process="@all"
     rendered="#{directPayment.getDirectPaymentLineSet().size() gt 1}"
     update="listDirectPaymentLines, container, totalAmount"
     immediate="true"
     ajax="false" />

When I click this button I need to update the panel which contains this button.

panelGroup:

<h:panelGroup id="listDirectPaymentLines">
<c:forEach var="directPaymentLine" items="#{step.directPaymentLineList}" varStatus="counter">
    <r:propertyRow>
        <r:property id="costType-#{counter.index}" width="HALF" label="Cost Type" value="#{directPaymentLine.claimCostType}"
                    objectList="#{entityListCache.getAllClaimCostTypes(entityInstance.costType, claim)}"
                    onChangeActionObject="#{step}" onChangeActionMethod="changeDirectPaymentLine"
                    reRenderPropertiesOnChange="totalAmount, claimDeductible-#{counter.index}, deductibleInRespectOfClaim-#{counter.index}"
                    hideNoSelectionLabel="false" required="true" />
        <c:if test="#{!step.hasCoinsurance}">
            <r:property id="amount-#{counter.index}" width="QUARTER" label="Amount" value="#{directPaymentLine.amount}"
                        onChangeActionObject="#{step}" onChangeActionMethod="changeDirectPaymentLine"
                        reRenderPropertiesOnChange="totalAmount" required="true" />
        </c:if>
        <r:property id="deleteButton-#{counter.index}" type="CUSTOM">
            <p:commandButton id="deleteDirectPaymentLine-#{counter.index}"
                             icon="fa fa-close Fs16 white"
                             action="#{step.deleteDirectPaymentLine(directPaymentLine)}"
                             process="@all"
                             rendered="#{directPayment.getDirectPaymentLineSet().size() gt 1}"
                             update="listDirectPaymentLines, container, totalAmount"
                             immediate="true"
                             ajax="false" />
        </r:property>
        <c:if test="#{step.hasCoinsurance}">
            <r:propertyRow>
                <r:property width="HALF" id="hundredPercentAmount-#{counter.index}" label="100% Amount" value="#{directPaymentLine.oneHundredPercentAmount}"
                            onChangeActionObject="#{step}" onChangeActionMethod="changeHundredPercentAmount"
                            reRenderPropertiesOnChange="totalAmount, totalHundredPercentAmount, amount-#{counter.index}" />
                <r:property width="HALF" id="amount-#{counter.index}"  label="Our Share Amount" value="#{directPaymentLine.amount}"
                            onChangeActionObject="#{step}" onChangeActionMethod="changeDirectPaymentLine"
                            reRenderPropertiesOnChange="totalAmount, totalHundredPercentAmount, hundredPercentAmount-#{counter.index}" />
            </r:propertyRow>
        </c:if>
    </r:propertyRow>
    <r:propertyRow>
        <r:property width="HALF" label="Claim deductible" id="claimDeductible-#{counter.index}" value="#{directPaymentLine.claimDeductible}"
                    objectList="#{step.getClaimDeductibles(directPaymentLine)}"
                    rendered ="#{step.isRenderClaimDeductible(directPaymentLine)}"
                    displayProperty="amountDisplayDescription"
                    onChangeActionObject="#{step}" onChangeActionMethod="changeDirectPaymentLine"
                    hideNoSelectionLabel="false" required="true" />

        <r:property label="Deductible In Respect of" id="deductibleInRespectOfClaim-#{counter.index}" value="#{directPaymentLine.deductibleInRespectOf}"
                    width="HALF"
                    objectList="#{entityListCache.getAllDeductibleInRespectOfs(directPaymentLine.deductibleInRespectOf)}"
                    rendered="#{step.isRenderClaimDeductible(directPaymentLine)}"
                    onChangeActionObject="#{step}" onChangeActionMethod="changeDirectPaymentLine"
                    hideNoSelectionLabel="false" required="true" />
    </r:propertyRow>
</c:forEach>

The Delete method which is called from the command button is below:

public void deleteDirectPaymentLine(DirectPaymentLine dpl) {
    linkedHashSet.remove(dpl);
    directPaymentLineList.remove(dpl);
    //directPayment.setDirectPaymentLineSet(linkedHashSet);
    directPaymentService.deleteDirectPaymentLine(directPayment, dpl);
    if (hasCoinsurance) {
        directPaymentService.recalculateTotalHundredPercentAmount(directPayment);
    }
}

May someone knows why the panel is not updated? When I debug the delete method, I can see that the right object is deleted but it's not updated in the view. If I delete the last element of the list, works properly, but if I delete something else then a different line is deleted. Example:

  • PObject 1
  • PObject 2
  • PObject 3
  • PObject 4

When the object 4 is deleted the new list contains only the first 3 elements. But in case of deletion of the Object 3 or 2 then the last line is deleted again, but only in the view.

Need somejow to enforce the panelGroup to be updated with the new values.

pik4
  • 1,283
  • 3
  • 21
  • 56
  • You have an `ajax='false'` so the `update` is useless – Kukeltje Nov 14 '17 at 14:37
  • @Kukeltje true, but the problem is still here... – pik4 Nov 14 '17 at 14:48
  • So what did you change? – Kukeltje Nov 14 '17 at 14:56
  • @Kukeltje even if you delete the update the problem is still there! – pik4 Nov 14 '17 at 15:03
  • Yes but since you return 'void' from the action that is expected https://stackoverflow.com/questions/8744162/difference-between-returning-null-and-from-a-jsf-action. Next time create a [mcve] to narrow down the scope of the problem. Easy to do and saves us work – Kukeltje Nov 14 '17 at 15:08
  • Possible duplicate of [Difference between returning null and "" from a JSF action](https://stackoverflow.com/questions/8744162/difference-between-returning-null-and-from-a-jsf-action) – Kukeltje Nov 14 '17 at 15:08
  • @Kukeltje I think that you didn't get my point. I include everything to be more specific. The problem is with the update of panel. – pik4 Nov 14 '17 at 15:17
  • So, what I need to return in this case? – pik4 Nov 14 '17 at 16:08
  • Use ajax! (remove ajax=false) and re-add the `update` – Kukeltje Nov 14 '17 at 16:08
  • Did it and the same issue again. It removes the wrong line... – pik4 Nov 14 '17 at 16:11
  • 'same issue'??? not updating is something else than removing the wrong line! – Kukeltje Nov 14 '17 at 16:14
  • Oh and you hopefully know that the JSTL `c:foreach` is only executed once (on view build time)? So only NOT doing ajax and returning an empty string (as can be read in the link I posted) will re-build the full page – Kukeltje Nov 14 '17 at 16:17

0 Answers0