Injecting custom-type parameters with CDI and JSF

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

Tagged: 

This topic contains 1 reply, has 1 voice, and was last updated by  kalgon 1 year, 1 month ago.

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

    kalgon
    Participant

    Hi,

    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 {
        @Parameter
        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(CdiExpressionLanguageProvider.java:136):

    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) ?

    Regards,
    Xavier

    • This topic was modified 1 year, 1 month ago by  kalgon. Reason: typo
    #27764

    kalgon
    Participant

    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.