1

I got an issue for a while and I can't get rid of it. In my data table I have a column with a button to display a dialog with further information on click.

When I click the first time on the button the dialog opens with the right values, but when I click a second time on button of the same row or any other the values aren't displayed because my event handler findStfPack receive a null value attribute.

I tried to pass the PackageData object to be displayed directly to the method as parameter:

<p:column width="60">
  <p:commandButton oncomplete="PF('dlgViewStfPack').show()" 
                   update="search:dlgViewStfPackId"
                   value=""
                   title="#{msg['button.search']}"
                   action="#{budgetViewFulfiledController.findStfPack(_item.stfPack)}"
                   process="@this"/>
</p:column>

Handler method in view controller:

public void findStfPack(PackageData event){
  System.out.println("event: "+event.getPackId());
  stfPack= event;
}

Or with primefaces action event:

<p:column width="60">
  <p:commandButton oncomplete="PF('dlgViewStfPack').show()"
                   update="search:dlgViewStfPackId"
                   value=""
                   title="#{msg['button.search']}"
                   actionListener="#{budgetViewFulfiledController.findStfPack}"
                   process="@this">
    <f:attribute name="pack" value="#{_item.stfPack}"/>
  </p:commandButton>
</p:column>

Handler method in view controller:

public void findStfPack(ActionEvent event){
  PackageData packageData= (PackageData)event.getComponent().getAttributes().get("pack");
  System.out.println("event: "+packageData.getPackId());
  stfPack= packageData;
}

The dialog:

<p:dialog id="dlgViewStfPackId"
          header="#{budgetViewFulfiledController.stfPack.staff.stfName} - Package salarial"
          modal="true"
          widgetVar="dlgViewStfPack">
  <div class="groupDataBox">
    <my:outputCurrentPackage currPack="#{budgetViewFulfiledController.stfPack}"/>
  </div>
</p:dialog>

And the outcome is the same in the 2 scenarios: on the first event trigger the value is properly passed and displayed but on the second event trigger I got a NullPointerException.

I should specify that, I don't know why but without the update="search:dlgViewStfPackId" the values are not displayed in the dialog.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Rémi Hirtz
  • 113
  • 3
  • 14

1 Answers1

0

I don't know exactly the reason, but if you don't update dialog, data can't refresh, it's will be cached the last result. Try to change like this :

XHMTL

<p:column width="60">
    <p:commandButton oncomplete="PF('dlgViewStfPack').show()"
               update="@([$id=dlgViewStfPackId])"
               value=""
               title="#{msg['button.search']}"
               action="#{budgetViewFulfiledController.findStfPack(_item.stfPack)}"
               process="@this">

    </p:commandButton>
</p:column>

JAVA

public void findStfPack(PackageData pd){
    System.out.println("event: "+pd.getPackId());
    this.stfPack= pd;
}

If it's not working, try to process ID_TABLE

Tea
  • 873
  • 2
  • 7
  • 25
  • Keep in mind it **does** work **_once_** as OP stated and OP does this: `update="search:dlgViewStfPackId"` which is in my opinion updating the dialog, so at most the value in it is wrong, maybe add that to your answer, but in that case this question is a duplicate of https://stackoverflow.com/questions/8634156/how-to-find-out-client-id-of-component-for-ajax-update-render-cannot-find-compo?noredirect=1&lq=1 and OP should get an error (maybe depending on running in development mode or not) and without the update attribute it does not even work once, so it is 'ok' – Kukeltje Apr 14 '17 at 10:32