Injecting custom-type parameters with CDI and JSF

Splash Forums Rewrite Users Injecting custom-type parameters with CDI and JSF


This topic contains 1 reply, has 1 voice, and was last updated by  kalgon 4 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #27762



    What would be the correct way to inject custom-typed parameters (for which a JSF converter exists) into a JSF bean that has a CDI scope (@RequestScoped) ?

    I’ve tried something like this:

    public class BankAccountNumber { ... } // My custom type
    @FacesConverter(forClass = BankAccountNumber.class)
    public class BankAccountNumberConverter implements Converter { ... }
    @Model // @Named + @javax.enterprise.context.RequestScoped (CDI scope, not JSF)
    @Join(path = "/account/{bankAccountNumber}", to = "/account.xhtml")
    public class AccountBean {
        private BankAccountNumber bankAccountNumber;

    I get the following exception:

    Error during [InboundRewrite [GET url=http://localhost:8080/myapp/account/1234-5678-90, flow=UN_HANDLED, dispatchResource=null]] while executing rule [.addRule(Join.path(“/account/{bankAccountNumber}”).to(“/account.xhtml”))]
    Caused by: java.lang.IllegalArgumentException: Cannot convert 1234-5678-90 of type class java.lang.String to class com.mycompany.BankAccountNumber

    The problem seems to be in CdiExpressionLanguageProvider.setValue(

    ve.setValue(context, factory.coerceToType(value, ve.getType(context)));

    Instead of asking the ExpressionFactory to coerce the value to the given type, shouldn’t it leverage Rewrite’s built-in conversion facility (org.ocpsoft.rewrite.param.Converter<T>, org.ocpsoft.rewrite.spi.ConverterProvider, org.ocpsoft.rewrite.faces.artifact.FacesConverterProvider) ?


    • This topic was modified 4 months, 2 weeks ago by  kalgon. Reason: typo


    Nevermind, I just had to use @Convert and @Deferred on my property.

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

You must be logged in to reply to this topic.

Comments are closed.