0

I am trying to do a deactivation method, which will show the status ("DEACTIVATED","ACTIVATED") of the account on the commandbutton, and when i clicked on the commandButton, it will either activate or deactivate the account based on the current status. Once I confirm, the commandButton will be immediately updated to its current status.

I have the following code and I would like to update my commandButton after completion of my actionlistener in "confirmDeactivateDialog" or "confirmActivateDialog". I tried using update="a,b" at those two confirmDialog tag but it doesn't work. Any suggestions?

<p:column headerText="Status" style="text-align: center">  
    <p:commandButton id='a' rendered="#{bean.isActivated(account_status)==true}" oncomplete="PF('deactivateDialog').show();" value="Activated">
       <f:setPropertyActionListener value="#{searchEmployeeResultList}" target="#{bean.selectedEmployee}"/>
    </p:commandButton>

    <p:confirmDialog id="confirmDeactivateDialog" header="Confirm Deactivation" widgetVar="deactivateDialog">
       <p:commandButton id="Deactivate" value="Ok" oncomplete="PF('deactivateDialog').hide();" actionListener="#{AccountManagedBean.deactivate}"/>
    </p:confirmDialog>

    <p:commandButton id="b" rendered="#{bean.isActivated(account_status)==false}" oncomplete="PF('activateDialog').show();" value="Deactivate">
       <f:setPropertyActionListener value="#{searchEmployeeResultList}" target="#{bean.selectedEmployee}"/>
    </p:commandButton>

    <p:confirmDialog id="confirmActivateDialog" header="Confirm Activation" widgetVar="activateDialog">
       <p:commandButton id="Activate" value="Ok" oncomplete="PF('activateDialog').hide();" actionListener="#{AccountManagedBean.activate}"/>
    </p:confirmDialog>

</p:column> 
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ayampenyet
  • 241
  • 1
  • 2
  • 15
  • "It doesn't work?" - what exactly did not work? Any error messages? Maybe something like "Component 'a' not found"? – Manuel Sep 05 '14 at 11:47
  • @Manuel: hint: OP declared the dialog inside a column. – BalusC Sep 05 '14 at 11:48
  • Right. Then the generated id of `p:commandButton` will not be just `a` or `b`. Check the generated HTML source code of JSF. JSF will generate a unique ID for each row in the datatable and this ID will be the prefix of your `a` element. Use a relative update path for `a` and `b`. – Manuel Sep 05 '14 at 11:51
  • @Manuel There is no error ;( it's just that the commandButton won't get updated. – ayampenyet Sep 05 '14 at 11:51
  • @Manuel So do you mean update= ":
    :a, :
    :b" ?
    – ayampenyet Sep 05 '14 at 11:59
  • Yes, or `:dataTableName::a`, or just `:a`. But this way all `a` elements will be updated, in every row :/ – Manuel Sep 05 '14 at 12:21
  • For this kind of UI behavior, the rule of thumb is to update the parent component of the desired target component. – Yamada Sep 05 '14 at 12:42
  • @Manuel Sorry, i have tried of them but i got a javax.faces.FacesException: Cannot find component with expression ":result::a" referenced from "employeeManagementForm:result:0:Deactivate". ;/ – ayampenyet Sep 05 '14 at 13:13
  • @balusC now I was wondering if my code is even correct to update the color and value of the commandButton upon completion of the method. I have tried many ways but failed :/ – ayampenyet Sep 05 '14 at 15:47

1 Answers1

0

try update="a b"

with no comma between them

sara.elkady
  • 29
  • 1
  • 7