I think this is what you're trying to do, but I haven't tested it.  The key
bit is the <construct class=...> references a factory class instead of what
the factory should generate.  If this works, the general solution is to make
the factory take a "className" and "constructorArgument" property and use
reflection in the createStateObject method.  At least that serves a broad
enough purpose to disguise the fact that it's an ugly kludge.

-Steve

    <service-point id="BooleanFactory" 
interface="org.apache.tapestry.engine.state.StateObjectFactory">
        <invoke-factory>
            <construct class="org.frustrated.BooleanFactory">
                <set property="booleanState" value="false"/>
            </construct>
        </invoke-factory>
    </service-point>

public class BooleanFactory implements StateObjectFactory {
        private booleanState;

        public Boolean getBooleanState() {
                return booleanState;
        }
        public void setBooleanState(boolean booleanState) {
                This.booleanState = booleanState;
        }
        public Object createStateObject() {
                return new Boolean(booleanState);
        }
}
-----Original Message-----
From: Danny Mandel [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 01, 2006 2:52 PM
To: Tapestry users
Subject: Re: How to pass a parameter to an ASO constructor?

Ping? Short story is that I'm attempting to pass a constructor argument 
(in this case, the boolean false) when creating my ASO.

I've continued searching for this and am still stuck.  The closest thing 
I found on the wiki and attempted to adapt to my needs was this:

    <contribution configuration-id="tapestry.state.ApplicationObjects">
        <state-object name="isToolTryout" scope="session">
            <invoke-factory object="service:BooleanFactory"/>
        </state-object>
    </contribution>

    <service-point id="BooleanFactory" 
interface="org.apache.tapestry.engine.state.StateObjectFactory">
        <invoke-factory>
            <construct class="java.lang.Boolean">
                <boolean>false</boolean>
            </construct>
        </invoke-factory>
    </service-point>

Which results in the following error when attempting to access the ASO 
for the first time:

---------
Unable to construct service org.tolweb.tapestry.BooleanFactory: Instance 
factory for service org.tolweb.tapestry.BooleanFactory returned false 
which does not implement the 
org.apache.tapestry.engine.state.StateObjectFactory interface declared 
by the extension point.
---------

I'll happily write up a howto on the wiki if anyone can provide insight 
to help this work.

Thanks,
Danny
> Hi all,
>
> I'm trying to figure out how to pass a constructor argument when 
> constructing an ASO.  I have a java.lang.Boolean, and it *needs* to 
> have a parameter passed in the constructor (no empty-arg constructor 
> exists).  I know this ought to be simple, but I don't see any 
> documentation explaining the proper way to do this.  This current way 
> doesn't work:
>
>        <state-object name="isToolTryout" scope="session">
>            <invoke-factory service-id="hivemind.BuilderFactory">
>                <construct class="java.lang.Boolean">
>                    <boolean>false</boolean>
>                </construct>
>            </invoke-factory>
>        </state-object>
>
> Any hints would be greatly appreciated.
>
> Thanks,
> Danny
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to