Mapping URL param to bean field using JSF converter

Splash Forums Rewrite Users Mapping URL param to bean field using JSF converter

This topic contains 2 replies, has 2 voices, and was last updated by  Headwinds 2 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26011

    Headwinds
    Participant

    Hi there. I’m trying to map an integer URL parameter to an entity field on my backing bean using Rewrite.

    public Configuration getConfiguration(ServletContext context) {
    	return ConfigurationBuilder.begin()
    		.addRule(
    			Join.path("/contact/{contact}").to("/pages/contact.xhtml")
    		).where("contact").bindsTo(
    			PhaseBinding.to(El.property("contactBean.contact")).after(PhaseId.RESTORE_VIEW)
    		);
    }

    ContactBean.contact is of type Contact, a Hibernate entity with an integer ID. So my goal is to navigate to the URL /contact/17, have Rewrite use my existing JSF converter to convert “17” to the appropriate Contact object, then set that object into ContactBean.contact. How can I make Rewrite use my JSF converter in this way?

    I’m using Rewrite 2.0.11 and JSF 2.

    • This topic was modified 2 years, 4 months ago by  Headwinds.
    #26014

    You should try something like this:

    PhaseBinding.to(El.property("contactBean.contact")).after(PhaseId.RESTORE_VIEW)
            .convertedBy(FacesConverter.forType(Integer.class))
    
    #26016

    Headwinds
    Participant

    Thank you, that works! I had tried .convertedBy previously, but I appended it to the end of the .bindsTo call – it works much better your way.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed.