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 thoughts on “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. 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.

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s