2

I have a h:form that contains a p:defaultCommand, which defines its scope as that form. However, I also have a p:dialog, which I want to have a different default command. I can put another p:defaultCommand in the dialog, and set its scope to be the dialog, but the default command in the form takes precedence over it. I looked at the resulting HTML, and the dialog is simply an element inside the form. Is there a way to have these two elements use different default commands?

codebreaker
  • 763
  • 1
  • 7
  • 24

2 Answers2

5

There is a design problem. You're supposed to put different forms each in its own <h:form>. Moreover, each dialog should always have its own <h:form>.

That'll immediately solve this peculiar problem with different default commands in each form.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Make sure the dialog with its form is NOT nested inside the other form – Kukeltje Mar 24 '15 at 23:32
  • Yeah, I think that's the problem. The dialog is created inside the form. I tried using appendToBody="true", but that seemed to have weird side effects. – codebreaker Mar 25 '15 at 14:25
  • Kukeltje means that you shouldn't have `.........` (which is [illegal](http://validator.w3.org) in HTML), but `.........`. As to `appendToBody="true"`, if the dialog doesn't have its own form, then it would indeed cause it not being inside a form anymore. See also a.o. http://stackoverflow.com/questions/18958729/pcommandbutton-action-doesnt-work-inside-pdialog/18958907#18958907 – BalusC Mar 25 '15 at 14:48
  • Right, I guess I should have said the dialog has its own form, and it was being generated from within another form, causing illegal nesting. I understand that part. But in the linked answer, they have `...`. Is this correct? It sounds like you're saying I need to have the form contain the dialog. – codebreaker Mar 25 '15 at 15:00
  • 1
    The dialog should have its own form. I.e. put the form inside the dialog. Do not put the dialog in a form. – BalusC Mar 25 '15 at 15:08
0

I had a simular issue with primefaces dialog:

My dialog was outside a form, but on runtime it still got added inside the form. I assume this had something to do with the <ui:include> tags I was using.

To make sure the dialog would be added outside the form I used the following on the dialog tag:

appendTo="@(body)"

This appends the dialog as a child of the body tag, making sure it is not a child of the form.

Ruben Pirotte
  • 386
  • 2
  • 11