You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Cagan <cs...@teknolabs.com> on 2006/01/27 17:06:50 UTC

forcing Login

Hello all,

I am quite new to Tapestry, trying to leave Struts behind...

I'm using Tapestry 4.0 running on Tomcat 5.5.15.

I'm trying to setup a system where there is a common base class for  
all Pages that require a user to login first.

This is going to be a bit lenghty as I want to give all the details  
of my setup...

For that, I wrote a simple AAdminPage :

    @InjectStateFlag("user")
     public abstract boolean getUserExists();

     @InjectPage("Login")
     public abstract Login getLoginPage();

     /**
      * @see  
org.apache.tapestry.event.PageValidateListener#pageValidate 
(org.apache.tapestry.event.PageEvent)
      */
     public void pageValidate(PageEvent pe) {
         if (!getUserExists()){
             Login login = getLoginPage();
             login.setNextPage(this);
             throw new PageRedirectException(login);
         }
     }


and Login:

@InjectPage("Home")
     public abstract Home getHomePage();

     @Persist("user")
     public abstract User getUser();
     public abstract void setUser(User usr);

     public IPage doSubmit(){
         log.fine("-->doSubmit()");
         try{
            setUser(UserManager.authenticate(getEmail(), getPassword 
()));
            return getNextPage() == null ? getHomePage() : getNextPage 
();
         }catch(AuthenticationException ae){
            return null;
         }
     }

     public abstract void setEmail(String email);
     public abstract void setPassword(String password);
     public abstract String getEmail();
     public abstract String getPassword();
     public abstract void setNextPage(IPage page);
     public abstract IPage getNextPage();


and Home is an empty class that simply extends AAdminPage..

I have in META-INF/hivemodule.xml:
<?xml version="1.0"?>
<module id="com.teknolabs.teknotrip" version="1.0.0">
     <contribution configuration-id="tapestry.state.ApplicationObjects">
             <state-object name="user" scope="session">
                 <create-instance  
class="com.teknolabs.teknotrip.model.company.User"/>
             </state-object>
     </contribution>
</module>


When I try to go to localhost:8080/app, I get the following error:
"'user' is not a declared application state object."

which is happening inside pageValidate method of AAdminPage at ! 
getUserExists() line...

t what is it that I'm doing wrong here?

Thanks in advance.
Cagan






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


Tap 3, Workbench Chart

Posted by Gunna Satria <gu...@yahoo.com>.
Hi All,
  I already tried Workbench Chart. It run smoothly in Windows. But when i try it in
  Solaris it won't work. There is no error message. the image just don't show..
  Can someone enlight me?
  Thanks.
   
  Gunna

		
---------------------------------
 
 What are the most popular cars? Find out at Yahoo! Autos 

Re: forcing Login

Posted by Chris Conrad <cc...@vasoftware.com>.
It looks like you're confusing Tapestry by having both an ASO and a  
persistent page property with the same name.  Try changing your Login  
class to be annotated like this instead:

@Persist("userProperty")
public abstract User getUser();
public abstract void setUser(User usr);

Or, if you really meant to be using the ASO and not a persistent page  
property, use annotation @InjectState("user") instead of @Persist 
("user").

--Chris

On Jan 27, 2006, at 8:06 AM, Cagan wrote:

> Hello all,
>
> I am quite new to Tapestry, trying to leave Struts behind...
>
> I'm using Tapestry 4.0 running on Tomcat 5.5.15.
>
> I'm trying to setup a system where there is a common base class for  
> all Pages that require a user to login first.
>
> This is going to be a bit lenghty as I want to give all the details  
> of my setup...
>
> For that, I wrote a simple AAdminPage :
>
>    @InjectStateFlag("user")
>     public abstract boolean getUserExists();
>
>     @InjectPage("Login")
>     public abstract Login getLoginPage();
>
>     /**
>      * @see  
> org.apache.tapestry.event.PageValidateListener#pageValidate 
> (org.apache.tapestry.event.PageEvent)
>      */
>     public void pageValidate(PageEvent pe) {
>         if (!getUserExists()){
>             Login login = getLoginPage();
>             login.setNextPage(this);
>             throw new PageRedirectException(login);
>         }
>     }
>
>
> and Login:
>
> @InjectPage("Home")
>     public abstract Home getHomePage();
>
>     @Persist("user")
>     public abstract User getUser();
>     public abstract void setUser(User usr);
>
>     public IPage doSubmit(){
>         log.fine("-->doSubmit()");
>         try{
>            setUser(UserManager.authenticate(getEmail(), getPassword 
> ()));
>            return getNextPage() == null ? getHomePage() :  
> getNextPage();
>         }catch(AuthenticationException ae){
>            return null;
>         }
>     }
>
>     public abstract void setEmail(String email);
>     public abstract void setPassword(String password);
>     public abstract String getEmail();
>     public abstract String getPassword();
>     public abstract void setNextPage(IPage page);
>     public abstract IPage getNextPage();
>
>
> and Home is an empty class that simply extends AAdminPage..
>
> I have in META-INF/hivemodule.xml:
> <?xml version="1.0"?>
> <module id="com.teknolabs.teknotrip" version="1.0.0">
>     <contribution configuration- 
> id="tapestry.state.ApplicationObjects">
>             <state-object name="user" scope="session">
>                 <create-instance  
> class="com.teknolabs.teknotrip.model.company.User"/>
>             </state-object>
>     </contribution>
> </module>
>
>
> When I try to go to localhost:8080/app, I get the following error:
> "'user' is not a declared application state object."
>
> which is happening inside pageValidate method of AAdminPage at ! 
> getUserExists() line...
>
> t what is it that I'm doing wrong here?
>
> Thanks in advance.
> Cagan
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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: forcing Login

Posted by Aaron Bartell <al...@gmail.com>.
 
I had the same problem awhile back, see thread:
http://www.mail-archive.com/tapestry-user@jakarta.apache.org/msg11419.html

I kept searching around and here is the solution I came up with.  Implement
PageAttacheListener on your BasePage extending class and implement the
PageAttachListener like so:

---UserList.java---
public abstract class UserList extends BasePage implements
PageAttachListener {
...
    public void pageAttached(PageEvent event) {
        if (!getUserVisit().isLoggedIn()) {
            throw new PageRedirectException("Login");
        }
    }
...
    @InjectState("visit")
    public abstract UserVisit getUserVisit();
}


---UserVisit.java---
import java.io.Serializable;
public class UserVisit implements Serializable {
    boolean loggedIn = false;
    public UserVisit() {
    }
    public boolean isLoggedIn() {
        return loggedIn;
    }
    public void setLoggedIn(boolean loggedIn) {
        this.loggedIn = loggedIn;
    }
}



---hivemodule.xml---
<?xml version="1.0"?>
<module id="app" version="1.0.0" package="services">

	<contribution configuration-id="tapestry.url.ServiceEncoders">
		<page-service-encoder id="page" extension="html"
service="page" />
	</contribution>

	<contribution configuration-id="tapestry.state.ApplicationObjects">
		<state-object name="visit" scope="session">
			<create-instance
class="com.mowyourlawn.session.UserVisit" />
		</state-object>
	</contribution>	

</module>

At first I thought I wanted a catchall like I had with JSF
(http://mowyourlawn.com/blog/?p=6) but then I realized that method required
me to hard code the page names into the listener.  So with this Tapestry
method it is still more or less hard coded, but you don't have to worry
necessarily about when your page names change. (i.e. UserList changes to
Users)

I am working on a Tapestry 4.0 CRUD (Create, Read, Update, Delete)
application that has a lot of these tidbits that people need but aren't
necessarily apparent how to do them based on the Tapestry documentation.

HTH,
Aaron Bartell
http://mowyourlawn.com/blog


-----Original Message-----
From: Cagan [mailto:cs327@teknolabs.com] 
Sent: Friday, January 27, 2006 10:07 AM
To: tapestry-user@jakarta.apache.org
Subject: forcing Login

Hello all,

I am quite new to Tapestry, trying to leave Struts behind...

I'm using Tapestry 4.0 running on Tomcat 5.5.15.

I'm trying to setup a system where there is a common base class for all
Pages that require a user to login first.

This is going to be a bit lenghty as I want to give all the details of my
setup...

For that, I wrote a simple AAdminPage :

    @InjectStateFlag("user")
     public abstract boolean getUserExists();

     @InjectPage("Login")
     public abstract Login getLoginPage();

     /**
      * @see
org.apache.tapestry.event.PageValidateListener#pageValidate
(org.apache.tapestry.event.PageEvent)
      */
     public void pageValidate(PageEvent pe) {
         if (!getUserExists()){
             Login login = getLoginPage();
             login.setNextPage(this);
             throw new PageRedirectException(login);
         }
     }


and Login:

@InjectPage("Home")
     public abstract Home getHomePage();

     @Persist("user")
     public abstract User getUser();
     public abstract void setUser(User usr);

     public IPage doSubmit(){
         log.fine("-->doSubmit()");
         try{
            setUser(UserManager.authenticate(getEmail(), getPassword ()));
            return getNextPage() == null ? getHomePage() : getNextPage ();
         }catch(AuthenticationException ae){
            return null;
         }
     }

     public abstract void setEmail(String email);
     public abstract void setPassword(String password);
     public abstract String getEmail();
     public abstract String getPassword();
     public abstract void setNextPage(IPage page);
     public abstract IPage getNextPage();


and Home is an empty class that simply extends AAdminPage..

I have in META-INF/hivemodule.xml:
<?xml version="1.0"?>
<module id="com.teknolabs.teknotrip" version="1.0.0">
     <contribution configuration-id="tapestry.state.ApplicationObjects">
             <state-object name="user" scope="session">
                 <create-instance
class="com.teknolabs.teknotrip.model.company.User"/>
             </state-object>
     </contribution>
</module>


When I try to go to localhost:8080/app, I get the following error:
"'user' is not a declared application state object."

which is happening inside pageValidate method of AAdminPage at ! 
getUserExists() line...

t what is it that I'm doing wrong here?

Thanks in advance.
Cagan






---------------------------------------------------------------------
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