1

In my .xhtml file I have a button which calls a method from my ManagedBean. That method should run some tests and if those test are failing I should display a pop-up with an warning or an error. The warning should not affect the future flow, but the error should stop it.

How can I launch a pop up from backend?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user6346756
  • 59
  • 11

1 Answers1

0

Simply put, you do not launch any pop-ups from back-end. Your backing beans have no understanding of the DOM or the browser. What you can do, however, is saving the state in a backing bean and render a given HTML or JavaScript block based on that state. For this you can use the rendered="#{mybean.myboolean}" attribute in conjunction with a update="elementID" on your button. When clicked, the button will re-render an element with the given ID on the server and inject it into the DOM. If it contains HTML or JS code for a pop-up, then it shows up.

See here for a nice example: Ajax update and submission using h:commandButton

Or you could try the JSF messages component: http://www.mkyong.com/jsf2/jsf-2-message-and-messages-example/

EDIT: since you seem to be using PrimeFaces, you might also want to look into Dialogs and Validation.

Community
  • 1
  • 1
Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74