You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dustin Frazier <ta...@frayzhe.net> on 2005/08/17 02:03:53 UTC

learning HiveMind

Does anyone know of a gentle HiveMind tutorial out there, either generic or 
Tapestry-specific?  I've read through all the HiveMind docs (twice) and pored 
over the HiveMind XML files for Tapestry, and although I understand 
conceptually what it provides, I'm still getting hung up on the terminology 
and how to configure the darn thing.

I want to start doing things like Application State Objects the "right" way 
using Tapestry 4, but it's still not at all obvious how to do it.  Until the 
documentation and examples are updated to show the new best practices, it's 
seems to have a pretty steep learning curve...

Dustin


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


Re: learning HiveMind

Posted by Adam Greene <ag...@iq-2000.com>.
There is a component binding prefix called "state:" that returns true if the 
object has been created.   See 
http://jakarta.apache.org/tapestry/UsersGuide/bindings.html for explanation.

----- Original Message ----- 
From: "Dustin Frazier" <ta...@frayzhe.net>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, August 16, 2005 11:57 PM
Subject: Re: learning HiveMind


>I figured out how to create my own non-Visit Application State Object and 
>inject it into my default page class using Java 1.5 annotations (very 
>cool).  My hivemodule.xml has:
>
> <contribution configuration-id="tapestry.state.ApplicationObjects">
>   <state-object name="session-state" scope="session">
>     <create-instance class="net.foo.SessionState"/>
>   </state-object>
> </contribution>
>
> One problem I'm having, however.  I have a common Border component for 
> each of my pages, and it includes some conditional logic to show either a 
> Login or Logout link depending on whether there's a user currently logged 
> in.  The conditional for this looks like:
>
>   <span jwcid="@If" condition="ognl:page.state != null && page.state.user 
> != null">
>     <a href="#" jwcid="@DirectLink" listener="listener:logout">Logout</a>
>   </span>
>   <span jwcid="@Else">
>     <a href="#" jwcid="@PageLink" page="Login">Login</a>
>   </span>
>
> I converted this from a Tapestry 3 template that used engine.hasVisit to 
> avoid creating the Visit object just to check whether the user field on 
> visit was non-null.
>
> In the Tapestry 4 ASO scheme, however, the session state object is created 
> just by accessing the injected method on the page.  What's the right way 
> to only have the session state object created when I set one of it's 
> fields?  Do I need to use a factory service in my HiveMind configuration 
> somehow?
>
> Dustin
>
>
> ---------------------------------------------------------------------
> 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


Re: learning HiveMind

Posted by Dustin Frazier <ta...@frayzhe.net>.
Sorry to continue this conversation with myself in front of you all.  :)  I found the 
state: binding type, so I can check whether my session state object is created before 
accessing it and checking to see if there's a logged in user.  However, I can't combine 
this prefix with an ognl expression, correct?  This leaves me having to duplicate code in 
my template:

   <span jwcid="@If" condition="state:session-state">
     <span jwcid="@If" condition="ognl:page.state.user != null">
       <a href="#" jwcid="@DirectLink" listener="listener:logout">Logout</a>
     </span>
     <span jwcid="@Else">
       <a href="#" jwcid="@PageLink" page="Login">Login</a>
     </span>
   </span>
   <span jwcid="@Else">
     <a href="#" jwcid="@PageLink" page="Login">Login</a>
   </span>

So I guess I'm left creating a boolean property in my component that returns:

getPage().getEngine().getInfrastructure().getApplicationStateManager().exists("state") && 
getState().getUser() != null

Somehow, this doesn't feel like a huge improvement over the old Visit approach.  What 
about the possibility of having state injection create an "exists" method in addition to 
the getter?  It's bound to be a common check if people are trying to delay the creation of 
session state...

Dustin


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


Re: learning HiveMind

Posted by Dustin Frazier <ta...@frayzhe.net>.
I figured out how to create my own non-Visit Application State Object and inject it into 
my default page class using Java 1.5 annotations (very cool).  My hivemodule.xml has:

<contribution configuration-id="tapestry.state.ApplicationObjects">
   <state-object name="session-state" scope="session">
     <create-instance class="net.foo.SessionState"/>
   </state-object>
</contribution>

One problem I'm having, however.  I have a common Border component for each of my pages, 
and it includes some conditional logic to show either a Login or Logout link depending on 
whether there's a user currently logged in.  The conditional for this looks like:

   <span jwcid="@If" condition="ognl:page.state != null && page.state.user != null">
     <a href="#" jwcid="@DirectLink" listener="listener:logout">Logout</a>
   </span>
   <span jwcid="@Else">
     <a href="#" jwcid="@PageLink" page="Login">Login</a>
   </span>

I converted this from a Tapestry 3 template that used engine.hasVisit to avoid creating 
the Visit object just to check whether the user field on visit was non-null.

In the Tapestry 4 ASO scheme, however, the session state object is created just by 
accessing the injected method on the page.  What's the right way to only have the session 
state object created when I set one of it's fields?  Do I need to use a factory service in 
my HiveMind configuration somehow?

Dustin


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