You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by gs...@smm.de on 2005/12/23 14:33:55 UTC

checking for a ASO-instance, without creating it - is this possible ?

Hi, there ! :)

On my homepage I want to display the current users name.

So I have to check if someone is logged in or not.

One of my main strategies is to create a session as late as possible - so I
need a solution to check if there is an instance of my ASO or not.

I tried the following:

in hivemodule.xml:

     <contribution configuration-id="tapestry.state.ApplicationObjects">
          <state-object name="visitObject" scope="session">
          <create-instance class="de.gs.testpackage.MyVisit"/>
          </state-object>
     </contribution>

In MyHome.java:

     protected MyVisit visitObject;
     @InjectState("visitObject")
     public abstract MyVisit getVisitObject() ;
     public abstract void setVisitObject(MyVisit visit) ;

and

     if ((null == visitObject) || (getVisitObject().getUserId() ==-1))

But this will not work: visitObject seems to be null for ever :(

So is there a chance to check for an instance of on ASO without creating it
and the corresponding session ?

Thank you in advance !

Bye,

Gerald




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: checking for a ASO-instance, without creating it - is this possible ?

Posted by Andreas Andreou <an...@di.uoa.gr>.
gs@smm.de wrote:

>In MyHome.java:
>
>     protected MyVisit visitObject;
>     @InjectState("visitObject")
>     public abstract MyVisit getVisitObject() ;
>     public abstract void setVisitObject(MyVisit visit) ;
>
>and
>
>     if ((null == visitObject) || (getVisitObject().getUserId() ==-1))
>
>But this will not work: visitObject seems to be null for ever :(
>  
>
the visitObject field is never updated by Tapestry. Use
the getter, getVisitObject() to access it. This call will create the ASO
if it
does not yet exist.

>So is there a chance to check for an instance of on ASO without creating it
>and the corresponding session ?
>  
>
So, to check if an ASO exists through java code,
take a look at the org.apache.tapestry.engine.state.ApplicationStateManager
and call its boolean exists(String objectName) method.  For instance, |*
*if (
cycle.getInfrastructure().getApplicationStateManager().exists("visitObject")
)|

You can also check this in your templates with the state binding prefix,
<span jwcid="@If" condition="state:visitObject">
... do something
</span>

>Thank you in advance !
>
>Bye,
>
>Gerald
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org