RichFaces confirmation dialog #2 – custom tag

screenshot012.png

As 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.





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



   
	
	
	
   


Line #9 is a new name space for the custom tag.
Line #19 is where I’m using the new custom tag. I’m passing in two things; button label and the action to be invoked if the user clicks OK on the confirmation dialog.

confirmation.xhtml:

This page is very similar to the one from previous post. From the page avobe, I’m passing in two things: button label #{label} (line #10) and the action to be invoked #{action.save} (line #13). Facelets takes care of wiring the EL expressions automatically, so we don’t have to do anything special for that to work.









   Confirmation
   
      
         
	 
      
      
         
	 
	 
      
   



Now, to use it as a custom tag there are two more things we need to do. First, create a taglib file and then register in web.xml.

confirmation-taglib.xml

confirmation-taglib is a Facelet taglib file that defines the tag. In this case, we are simply pointing to the source file to create the custom tag. It should be placed under /WEB-INF directory (/WEB-INF/tags/confirmation-taglib.xml):




   http://richfaces.org/richx
	
	   confirm
	   tags/confirmation.xhtml
	

Finally, we need to register the custom taglib file in web.xml:


   facelets.LIBRARIES
   
	/WEB-INF/confirmation-taglib.xml
   

Confirmation dialog icon was downloaded form DesignMagus.

7 responses to “RichFaces confirmation dialog #2 – custom tag”

  1. Max,

    nice post …

    One minor correction: the mentioned path “/WEB-INF/tags/confirmation-taglib.xml” should be “/WEB-INF/confirmation-taglib.xml” according your web.xml specification.

    Another point is that you can use this component only once per page as the id has to be unique. I tried to pass the id, but the EL resolvement does not work for something like #{rich:component(‘#{id}’)} 😦

    And finally I am facing another EL problem: if I pass an action “#{user.logout} to the component, I receive a PropertyNotFoundException as Facelets wants to resolve the action value as a property of my backing bean (tries to find getLogout instead of logout).

    So in fact I won’t be able to use the Facelets component templating in my project …

    Regards,
    Michael

  2. Thanks, I fixed the path error.

    There is a way to place multiple confirmation dialogs on the same page. It does involve passing the id as an argument. I’ll do a full post today or tomorrow to show how it’s done. It’s going to look like this:

    
    

    where richx:concat is a Facelets function (http://shrubbery.mynetgear.net/wiki/Facelets_String_Functions)

    
    ...
    
    

    then on the page:

    
    
  3. I am facing EL problem: if I pass an action Ò€œ#{user.logout} to the component, I receive a PropertyNotFoundException as Facelets wants to resolve the action value as a property of my backing bean.

  4. I tried Max’s solution on mkblog.exadel.com/ria/richfaces-confirmation-dialog-3 with the component ID.

    I am using the confirmation dialog for two different components on the same page. The text that is shown on the dialog box is different between the two components so I am adding it as an attribute of each component on the page.

    So, instead of:

    I am using:

    The correct text is being displayed depending on which component (button) is clicked.

    However, the action being executed is not correct. Always the first action (from the first button) is being executed.

    Buttons on the page:

    Can someone tell me please how can I enforce the correct action is being executed?

    Thank you.

  5. the method to be called will be in template? complicated to reuse it.

  6. @Robert – if you look at comments, I think there is an example of how to pass the action method name to the tag.

Leave a reply to Ela Cancel reply