Why are my @ Inject'ed fields equal to zero when using the converter with @Param?

I have a pretty simple setup here:

@Named
@ApplicationScoped
public class TalentIdConverter implements Converter {
    @EJB
    private EntityManagerDao em;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (Strings.isNullOrEmpty(value)) {
            return null;
        }
        return em.find(Talent.class, Long.parseLong(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return String.valueOf(((Talent) value).getId());
    }
}

// Manager.class
public class Manager {
    @Inject @Param(converterClass = TalentIdConverter.class, name = "talentId")
    private ParamValue<Talent> curTalent

    @PostConstruct
    public void init() {
        // use curTalent.getValue()
    }
}

But every time it TalentIdConverter.getAsObjectis called em, it is null. Can someone enlighten me why this is so? I also tried using @FacesConverterin the converter, but the behavior has not changed.

This is on Wildfly-8.0.0.Beta1 using Weld-2.1.0.CR1 and Omnifaces-1.6.3

+4
source share
1 answer

1.6.3 @Param(converterClass) . , new TalentIdConverter() - . , CDI ( @Named) @Param(converter):

@Inject @Param(converter = "#{talentIdConverter}", name = "talentId")
private ParamValue<Talent> curTalent;

, @FacesConverter("talentIdConverter") , , JSF ( EJB, ve OmniFaces 1.6):

@Inject @Param(converter = "talentIdConverter", name = "talentId")
private ParamValue<Talent> curTalent;

, @FacesConverter(forClass=Talent.class), .

@Inject @Param(name = "talentId")
private ParamValue<Talent> curTalent;

, BeanManager @Param(converterClass) . OmniFaces.

+3

All Articles