Factory method does not create objects properly
bogdanminciu.bogdan.minciu.yahoo.com Mar 15, 2008 11:55 AMHello,
It seems that my @Factory method is recognizing the created objects only in its command block. I have this class:
@Stateful
@Name("xtw")
@Scope(ScopeType.SESSION)
@AutoCreate
public class XTextSessionWrapper implements LocalXTextSessionWrapper {
...
    @In(required=false, create=true)
    @Out
    private XLanguage activeLanguage;
    public String getText(String identifier) {
        log.info("getText(1): identifier= #0, activeLanguage= #1", identifier, getActiveLanguage());
        XTextEntry xte = xTextEntryDAO.findXTextEntry(identifier, getActiveLanguage());
        log.info("getText(2): identifier= #0, activeLanguage= #1", identifier, getActiveLanguage());
        xte.getXtext();
    }
    @Factory(value="activeLanguage", autoCreate=true)
    public void initActiveLanguage() {
        XLanguage xl = xLanguageDAO.findXLanguageByIdentifier("ro");
        log.info("initActiveLanguage(1): activeLanguage initialized to #0", xl.getIdentifier());
        setActiveLanguage(xl);
        log.info("initActiveLanguage(1): activeLanguage initialized to #0", getActiveLanguage().getIdentifier());
    }
    public XLanguage getActiveLanguage() {
        return activeLanguage;
    }
    public void setActiveLanguage(XLanguage activeLanguage) {
        this.activeLanguage = activeLanguage;
    }
...
}
And i am calling the getText() method. The method calling is as expected:
- the injected activeLanguage is detecting that it has a null value,
- the initActiveLanguage() factory method is called
- then the getText() method is continuing its execution.
But, the problem is that when the application exists the @Factory method block, the created objects: activeLanguage is lost and reported again as null.
Here is the output:
12:43:48,203 INFO [XTextSessionWrapper] initActiveLanguage(1): activeLanguage initialized to ro 12:43:48,203 INFO [XTextSessionWrapper] initActiveLanguage(1): activeLanguage initialized to ro 12:43:48,703 INFO [XTextSessionWrapper] initActiveLanguage(1): activeLanguage initialized to ro 12:43:48,703 INFO [XTextSessionWrapper] initActiveLanguage(1): activeLanguage initialized to ro 12:43:48,703 INFO [XTextSessionWrapper] getText(1): identifier= com.brit.xcms.cms.Category.12.name, activeLanguage= null 12:43:49,234 INFO [XTextSessionWrapper] getText(2): identifier= com.brit.xcms.cms.Category.12.name, activeLanguage= null
Where did I went wrong? Why is the activeLanguage factoried
 value lost when i leave the initActiveLanguage() method?
Thanks in advance,
Bogdan.
 
     
     
     
    