Hi Nick,
Thanks for the response. Sorry, I didn't phrase my email right...I know
how to get references to Application State Objects in java code, but I
was trying to access the ApplicationStateManager so I could
programmatically find out whether a named ASO already existed (to avoid
unnecessarily creating a session). (The "state:" binding does this in
XML, but getting the result into java isn't an ideal solution.) I
finally figured out how to do it:
To inject the ApplicationStateManager into a Tapestry component, add:
<inject property="appStateMgr"
object="service:tapestry.state.ApplicationStateManager" />
to the component specification. I don't know the annotation equivalent.
This is what I was trying to do:
----------------------------------------------------------
I have an ASO, LoginASO (named "loginASO" in the ASM), containing the
method:
boolean isLoggedIn()
I wanted to create an isUserLoggedIn() method in my Tapestry component
that wouldn't create LoginASO if it didn't already exist. I added the
<inject> tag listed above, then added the following to my java
component class:
public abstract ApplicationStateManager getAppStateMgr();
public boolean isUserLoggedIn() {
if( !getAppStateMgr().exists("loginASO") )
return false;
return
((LoginASO)getAppStateMgr().get("loginASO")).isLoggedIn();
}
----------------------------------------------------------
Thanks,
Travis
On Sep 17, 2005, at 6:23, Nick Stuart wrote:
Ok, so what exactly are you trying to do Travis? If I am reading it
correctly you simply would to inject a state object (say a user class
that holds values for a visitor to your site).
If this IS what you want to do look below:
First, all your ASO are simple POJO's, nothing speical about them, so
make your User class and call it good. Next up is configuring hivemind
to know about it.
In your hivemodule.xml (if you dont have one, you need one in your
META-INF folder) you need to add the following few lines:
....
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="user" scope="session">
<create-instance class="User"/>
</state-object>
</contribution>
....
You can play with the scope and name values to fit your needs. Thats
all you need to do in hivemind.
Next, in your page/component class (doesnt matter which) you do the
following:
@InjectState("user")
public abstract User getUser();
There are similar xml elements for injecting state as well (dont use
them much so I cant remember them off the top of my head). But
anyways, thats the full process to adding a state object to your
application and accessing them in your page.
-Nick
On 9/16/05, Travis McLeskey <[EMAIL PROTECTED]> wrote:
I misunderstood what was going on here. I thought you were injecting
the ApplicationStateManager into a Tapestry page.
So: how do you inject the ApplicationStateManager into a Tapestry
page?
I see that Tapestry's StateBindingFactory gets a reference to the
ApplicationStateManager with the line
<set-object property="applicationStateManager"
value="infrastructure:applicationStateManager"/>
in tapestry.bindings.xml.
I don't understand why this isn't documented...am I the only one who
wants to access Application State Objects in the Java class?
Any help would be appreciated!
Thanks,
Travis
On Sep 16, 2005, at 9:21, Travis McLeskey wrote:
For those of us new to HiveMind, where does the <set-service> element
need to go in the HiveMind config file? I'm just trying to access my
ASO in java code.
Thanks,
Travis
Pete <pertl <at> gmx.org> writes:
does somebody know how to inject 'myState' into the marked
'MyFilter'
property 'injectedState' ????
Try:
<set-service
property="appStateMgr"
value="tapestry.state.ApplicationStateManager"/>
class MyFilter {
ApplicationStateManager appStateMgr;
MyState getInjectedState() {
return (MyState)appStateMgr.get("myState");
}
}
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]