7

I have a commandButton and a dialog. The problem is after the dialog box appears, it disappears(1-2 miliseconds later). Is there a problem with my commandbutton or its dialog issue?

<p:commandButton id="showDetailsButton"
     title="Details"
     onclick="details.show();"
     process="@this"
     update=":tabView:myForm:myDialogId"                                         
     icon="ui-icon-search">                          
</p:commandButton>


<p:dialog id="myDialogId"
      header="Details"
      widgetVar="details"
      resizable="false"
      height="600"
      width="450"                  
      >
//some stuff
</p:dialog>
Niks
  • 4,802
  • 4
  • 36
  • 55
Turgut Dsfadfa
  • 775
  • 6
  • 20
  • 42
  • Please read @BalusC's comments on my answer. You need to provide more details in the question! – Niks May 22 '13 at 13:33

3 Answers3

10

Changed onclick to oncomplete and now It's working perfectly.

<p:commandButton id="showDetailsButton"
 title="Details"
 oncomplete="details.show();"
 process="@this"
 update=":tabView:myForm:myDialogId"                                         
 icon="ui-icon-search">                          

Turgut Dsfadfa
  • 775
  • 6
  • 20
  • 42
3

By default a <p:commandButton> is rendered as

<button type="submit" ....> ... </button>

EDIT: Iff you've disabled ajax behavior by specifying ajax=false, please read comments below.

and hence it will trigger a Post Back. So your page makes a POST request to server and refreshes.

Btw, you don't need a PrimeFaces commandButton here, simply use

<input type="button" onclick="details.show()" value="Details"/>
Niks
  • 4,802
  • 4
  • 36
  • 55
  • I believe the OP's code is incomplete. The dialog will only disappear if the OP used `ajax="false"` or `update="someIdCoveringDialog"` or so. However, the current code doesn't do that. Perhaps the OP forgot the ``. The browser behavior is then unspecified. – BalusC May 22 '13 at 12:43
  • Oops! @BalusC you're right. I missed the default ajax behavior of command button. And yes, if the container itself is updating the dialog would disappear. So overall,I agree that the question is missing details! – Niks May 22 '13 at 13:31
  • It is clearly is in his question that there is an update (scroll to the right process="@this" update=":tabView:myForm:myDialogId" – roel May 23 '13 at 07:12
0

remove the process and update from your commandbutton. They refresh the page/section. And you don't want that.

roel
  • 2,005
  • 3
  • 26
  • 41
  • The `process` attribute doesn't do that and there's already no `update` attribute. – BalusC May 22 '13 at 12:43
  • 1
    In his code snippit I see clearly an update statement: update=":tabView:myForm:myDialogId" (scroll to the right) – roel May 23 '13 at 07:10
  • You're right about that @roel. I suppose he does want to update the contents of dialog on click. Perhaps he should update the container inside the dialog and not the dialog itself – Niks May 23 '13 at 10:38
  • What a bad code snippet, please edit so that I can retract the downvote. – BalusC May 23 '13 at 11:21
  • After all, he clearly want to update the contents of the dialog before showing it (e.g. to show the currently selected item). The solution is then not to remove the `update`. Also, the `process` attribute does not refresh the section at all. – BalusC May 23 '13 at 11:22