[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-2764) Factory method does not create objects properly
Matt Drees (JIRA)
jira-events at lists.jboss.org
Mon Sep 1 01:20:38 EDT 2008
[ https://jira.jboss.org/jira/browse/JBSEAM-2764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12427504#action_12427504 ]
Matt Drees commented on JBSEAM-2764:
------------------------------------
This code has a cyclic dependency in it. A component can't inject a value that is provided by a factory in the same class. Seam will now (JBSEAM-3362) detect this sort of cyclic dependency and throw an exception.
> Factory method does not create objects properly
> -----------------------------------------------
>
> Key: JBSEAM-2764
> URL: https://jira.jboss.org/jira/browse/JBSEAM-2764
> Project: Seam
> Issue Type: Bug
> Components: EJB3
> Affects Versions: 2.0.1.GA
> Reporter: Bogdan Minciu
>
> Hello,
> 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:
> 1. the injected activeLanguage is detecting that it has a null value,
> 2. the initActiveLanguage() factory method is called
> 3. 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?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list