RichFaces confirmation dialog

While out-of-the-box confirmation dialog is not yet available in RichFaces, I will show you how to build one. Tomorrow I will show how to make it more reusable by packaging it as a Facelet custom tag.

screenshot011.png

If Cancel is clicked then nothing happens. If OK is clicked then the value is saved.






.rich-mpnl-body {
	text-align: center
}





   
   
   

   



   Confirmation
   
      
         
	 
      
      
         
	 
      
   



Line #22 is a Save button. It launches the Confirmation dialog, it doesn’t actually invoke the save action.

Lines #28-42 is the modal panel. The modal panel is client-side only in this case as there is no form inside. Clicking on the Cancel button will hide the model panel and do nothing else. Clicking on the OK button will hide the modal panel and will also call the submit() function. submit() function is defined by a4j:jsFunction and basically sends an Ajax request to the server. It also allows to specify what action to call. The a4j:jsFunction component is very similar to a4j:commandButton (or a4j:commandLink(), but allows to perform an Ajax request from a Javascript code directly.

Confirmation dialog icon was downloaded form DesignMagus.

36 responses to “RichFaces confirmation dialog”

  1. […] promised, this is the same Confirmation dialog as here but now it’s packaged as a Facelet custom tag so it’s much easier to reuse. 1 2 3 4 5 6 […]

  2. I recieve this error always use rich:component, ‘rich:component’ not found

    i use
    richfaces-api-3.3.0.GA.jar
    richfaces-impl-3.3.0.GA.jar
    richfaces-ui-3.3.0.GA.jar

    why?? please help me

    75 ERROR [STDERR] java.lang.ClassNotFoundException: No ClassLoaders found for: org.richfaces.function.RichFunction
    10:51:04,275 ERROR [STDERR] at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)

    javax.faces.FacesException: javax.faces.FacesException: javax.faces.FacesException: javax.el.ELException: /web/mod/servicios/solicitudCliente.xhtml @165,68 onclick=”#{rich:component(‘confirmation’)}.show();return false”: Function ‘rich:component’ not found

  3. Make sure you don’t have an older version of RichFaces in class path where rich:component function wasn’t yet available.

  4. Matthais Müller Avatar
    Matthais Müller

    Hi Max,

    thanks for your nice post. I’m experiencing a strange behavior in the following case. I want to delete an item that is listed in a rich-datatable. Therefore, I am binding the ID of the item to the selectedId-property of the managed bean :

    When I use this WITHOUT the confirmation dialog, everthing works fine. But, when using the dialog to confirm the deletion, the value of selectedId (which is of type HtmlOutputText) isn’t the ID of the selected item. It’s ALWAYS the ID of the LAST item in the list. Do you have any idea what’s happening here?
    Thanks in advance
    Matthias

  5. Matthais Müller Avatar
    Matthais Müller

    Uh, the code was removed, so one more try:

    <rich:dataTable value=”#{bean.items}” var=”item”>
    <rich:column >
    <f:facet name=”header”>
    <h:outputText value=”ID” />
    </f:facet>
    <h:outputText value=”#{item.id}” binding=”#{bean.selectedId}” />
    </rich:column>

  6. Can you post the complete code (page and bean)? You can use http://tinypaste.com .

  7. Matthias Müller Avatar
    Matthias Müller

    Hi Max,
    I’ve just seen you answered. I need a few time to build an minimalistic example, but I’ll be back 😉

  8. Matthias Müller Avatar
    Matthias Müller

    Here we go:

    The managed bean:
    http://tinypaste.com/2093f

    The xhtml-page:
    http://tinypaste.com/b2252

    Hope the links work…

  9. You have a4j:jsFunction defined in each row. When the page is rendered, doSomething is overwritten by function in each new row. When you call it, it references the last function and you get the last record. Here is a good example how this should be done: http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=editDataTable

  10. Matthias Müller Avatar
    Matthias Müller

    OMG, that’s the simple but logic explanation of what’s happening!
    Shame on me, should have thought about that by myself.
    Anyway, thank you very much for your help!
    Greetings from Germany
    Matthias

  11. Hi Max

    I really enjoy reading all your tutorials but the problem is I always always get this error as soon as I put in the code for the rich:modal part in my jsp page

    #{..} is not allowed in template text

    I’m using tomcat 6.0.20 and richfaces-api-3.2.0.GA.jar

    No matter what I do the error will not go away. Any ideas? Thanks for the guides.

  12. Paste the entire page and error via http://tinypaste.com

  13. the jsp page hosted on tomcat

    http://tinypaste.com/e40213a

    the error message

    http://tinypaste.com/20ed7

    1. You can’t use #rich:component(‘id’) with plain HTML tags in JSP, only in Facelets. Use it with h:outputLink

  14. Thank you very much. I’ll try using facelets. Don’t need the JSP pages. I guess I can run the demo site examples now as well.

  15. In your example of custom facelets, the two values passed are the label and the action method. When I try passing the action method as done in your second example, tomcat thinks that save is a member variable in my bean class and expects a getSave() method for it to work. or could you provide the backing beans for the save method as well?

  16. I’m only passing the #{userBean}, not the actual method. The method would look like this:

    public void save () {
     ...
    }
    
  17. sorry if this is the wrong section but I’m wondering if you’ve written a tutorial on ExtendedDataTables or if it’s in your book. I’m wondering how to do this

    http://www.jboss.org/index.html?module=bb&op=viewtopic&t=112564&postdays=0&postorder=asc&start=0

    Lazy loading of data when using a datascroller on each request when a new page is loaded. I checked the live demo but not quite sure of small stuff like dataprovider/etc.

  18. I don’t have such example or blog post.

  19. @martin: I don’t see your code, please repost via pastie.org

  20. Oh yeah… sorry. Here it is:

    pages.xml with navigation rule for logout: http://pastie.org/1565574
    Snippet from menu.xhtml for the logout link (opens the dialog): http://pastie.org/1565580
    Snippet from modalPanelConfirm.xhtml: http://pastie.org/1565583

    I tried a bit around and it seems, that the action call from a4j:jsFunction get not be recognized by Seam, so that it doesn’t use the navigation rule from pages.xhtml.

    This results in a proper logout and a normal page refresh, which in turn will does not work because this page are only viewable for a logged in user. So a redirect to my login.xhtml with a warning that one should be logged in occurs.

    If I call the idenity.logout action from a normal s:link or a4j:commandLink pages.xml nav rules will be respected and it behaves normally.

    Thank you

  21. @martin: Intersting, the action from a4j:jsFunction is the same as in h:commandLink or a4j:commandLink. Are you sure the action is called? What if you set the navigation outcome directly in action attribute?

  22. Hi,

    Actually, i’m using this confirmation dialog on a back button. This button is need in order to advise the user that are going out without save the entity.
    As Martin i use Seam and in the same manner a4j:jsFunction get not be recognized by Seam.
    Obviously, if i use only a simple button the action is read and button send back to the previous page.
    I Attach the code adapted to my case.

    .rich-mpnl-body {
    text-align: center
    }

    Richiesta Conferma

    Protocolla Atto

    thanks in advance

  23. ok it’s impossibile attach the code.
    But it’s exactly the same of the example with the only difference that i haven’t input text in the form, but only a4j:commandButton and a4j:function that call an action that redirect to the previous page.
    thks

  24. @erik: See if you can navigate with a4j:jsFunction when using Seam but from a regular page (not from a modal panel). Just use a button and onclick call a4j:jsFunction.

  25. @max:
    Yes Im sure that the action will be called, because Seam will log me out (identity.logout is a method from Seam framework). The navigation rule in pages.xml will be ignored.

    When I call my own action, which will write some test stuff to stdout and then returns my desired page navigation it does NOT work either.
    see http://pastie.org/1573841

    I tried to call the a4j:jsFunction action without a modalpanel as you suggested for eric and it DID work!!
    see http://pastie.org/1573846

    I also tried to surround the modalpanel with the form but this did NOT work.
    see http://pastie.org/1573849

    It seems that the modalPanel is the bad guy!

    Thank you,
    Martin.

  26. @Martin: Looking at the 1st and 3d links, where do you actually call a4j:jsFunction?

    When I call my own action, which will write some test stuff to stdout and then returns my desired page navigation it does NOT work either.
    see http://pastie.org/1573841

    I also tried to surround the modalpanel with the form but this did NOT work.
    see http://pastie.org/1573849

  27. its the Ok button within my modalPanel.
    Snippet from modalPanelConfirm.xhtml: http://pastie.org/1565583

  28. @martin: Try replacing s:button with just a regular HTML button (input type=”button”). Let me know if that works.

  29. @max: Yes that worked. It had to do with the s:button from Seam. h:commandButton and a4j:commandButton works as well. Wondering why… anyway: Thank you for help!!
    Maybe you could this mention in your blog text above so that others don’t need to read all the tick-tock conversation.

  30. @martin: It’s probably a bug somewhere, probably in Seam. I’d go ahead an enter it into their Jira (or RichFaces).

  31. I don’t get it. It’s cool! But why would I need it? I there something I’m missing or can you just use this:

  32. Well, i meant this:
    onclick=”return confirm(‘Are you sure?’);”

  33. @Lars: You can definitely use the browser dialog, however, a pop-up gives you more options such as styling as the application, inserting content and modal and non-modal.

Leave a reply to Lars Cancel reply