New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes not working in managed converters #437

Closed
reiudo opened this Issue Feb 19, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@reiudo

reiudo commented Feb 19, 2018

Consider the following page snipped and converter implementation:

<h:form id="TestPage">
    <h:commandButton id="button" type="submit" value="Button 1" />
    <br/>
    <h:inputText id="someText" value="#{bean.someValue}" >
        <o:converter converterId="com.pass.project.jsf23test.TestConverter" foo="foo value" />
    </h:inputText>
    
</h:form>
@FacesConverter(value=TestConverter.NAME, managed=true)
public class TestConverter implements Converter<String> {

    public static final String NAME = "com.pass.project.jsf23test.TestConverter";

    @Inject @Any
    private Bean bean;
    
    private String foo;
    
    @Override
    public String getAsObject(FacesContext context, UIComponent component, String value) {
        System.out.println("getAsObject - foo: " + foo + " bean: " + bean);
        return value;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, String value) {
        return value;
    }
    
    public String getFoo() {
        return foo;
    }

    public void setFoo(String foo) {
        System.out.println("TestConverter.setFoo(foo): " + foo);
        this.foo = foo;
    }
}

With managed=false, foo will be populated correctly with foo value. Unfortunately ‘bean’ will be null then.

With managed=true foo won’t be populated (but bean has a value of course).

Environment: Omnifaces 3.0.0 and Mojarra 2.3.3.

@reiudo

This comment has been minimized.

Show comment
Hide comment
@reiudo

reiudo Feb 20, 2018

I've added a minimal project to reproduce the issue.

Jsf23TestWithOmnifaces3.zip

reiudo commented Feb 20, 2018

I've added a minimal project to reproduce the issue.

Jsf23TestWithOmnifaces3.zip

@reiudo

This comment has been minimized.

Show comment
Hide comment
@reiudo

reiudo Feb 20, 2018

Without @FacesConfig(version=Version.JSF_2_3) the attributes are working. But that is not an option.

reiudo commented Feb 20, 2018

Without @FacesConfig(version=Version.JSF_2_3) the attributes are working. But that is not an option.

@BalusC BalusC closed this in 91804e5 Feb 25, 2018

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Feb 25, 2018

Member

Fix is available in today's latest 3.1-SNAPSHOT. Please give it a try and let me know.

Workaround for OmniFaces 3.0: remove parameterized type from Converter (so it becomes raw), remove managed=true from annotation, use bean-discovery-mode="all" in beans.xml or put @Dependent on converter, then OmniFaces will continue to manage it and the <o:converter> will be able to set properties on it.

From OmniFaces 3.1 on, parameterized Converter<T> is now also recognized by OmniFaces-managed CDI injection (as it was in OmniFaces 2.x), but <o:converter> won't support JSF's managed=true for now. Internally, Mojarra wraps the converter instance in a decorating instance which doesn't at all have the necessary setter methods and thus the attributes are silently ignored. I have clarified <o:converter> javadoc on this.

Similarly for @FacesValidator and <o:validator>.

Thanks for reporting!

Member

BalusC commented Feb 25, 2018

Fix is available in today's latest 3.1-SNAPSHOT. Please give it a try and let me know.

Workaround for OmniFaces 3.0: remove parameterized type from Converter (so it becomes raw), remove managed=true from annotation, use bean-discovery-mode="all" in beans.xml or put @Dependent on converter, then OmniFaces will continue to manage it and the <o:converter> will be able to set properties on it.

From OmniFaces 3.1 on, parameterized Converter<T> is now also recognized by OmniFaces-managed CDI injection (as it was in OmniFaces 2.x), but <o:converter> won't support JSF's managed=true for now. Internally, Mojarra wraps the converter instance in a decorating instance which doesn't at all have the necessary setter methods and thus the attributes are silently ignored. I have clarified <o:converter> javadoc on this.

Similarly for @FacesValidator and <o:validator>.

Thanks for reporting!

@reiudo

This comment has been minimized.

Show comment
Hide comment
@reiudo

reiudo Feb 27, 2018

With OmniFaces 3.1-SNAPSHOT and without the managed="true" attribute the converter now works with properties and injected beans. Thanks for fixing!

Is there a release date already planned for OmniFaces 3.1?

reiudo commented Feb 27, 2018

With OmniFaces 3.1-SNAPSHOT and without the managed="true" attribute the converter now works with properties and injected beans. Thanks for fixing!

Is there a release date already planned for OmniFaces 3.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment