primefaces dialog disappears after show up
Asked Answered
D

4

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>
Dunstable answered 22/5, 2013 at 9:14 Comment(1)
Please read @BalusC's comments on my answer. You need to provide more details in the question!Game
D
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">                          

Dunstable answered 23/5, 2013 at 12:35 Comment(0)
G
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"/>
Game answered 22/5, 2013 at 9:16 Comment(3)
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 <h:form>. The browser behavior is then unspecified.Transilluminate
Oops! @Transilluminate 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!Game
It is clearly is in his question that there is an update (scroll to the right process="@this" update=":tabView:myForm:myDialogId"Transistor
T
0

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

Transistor answered 22/5, 2013 at 9:56 Comment(5)
The process attribute doesn't do that and there's already no update attribute.Transilluminate
In his code snippit I see clearly an update statement: update=":tabView:myForm:myDialogId" (scroll to the right)Transistor
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 itselfGame
What a bad code snippet, please edit so that I can retract the downvote.Transilluminate
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.Transilluminate
S
0

If there is another form you have created inside the form tag, you should make sure that it is outside, because unaware update operations can break the process.

Stomatology answered 28/3 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.