You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Otho <ta...@googlemail.com> on 2007/06/23 15:30:49 UTC

Re: T5 - Authentication filter

Hi all!
Was there a solution to this really strange ClassCastException already?

I have the same problem in the following circumstances:

public class Search extends BaseComponent
{
    @Component
    private Form simpleSearch;

    @ApplicationState
    private SimpleSearchString simpleSearchString;

    private String searchTerm; // wil be populated by the form;

    /* Form Handler */

    String onSuccess()
    {
        if (searchTerm == null)
            return null;


>>>>        getSimpleSearchString().setSearchTerm(searchTerm);
        return "ExtendedSearch";
    }

    public SimpleSearchString getSimpleSearchString()
    {
        return simpleSearchString;
    }

>>>> This line gives the following stacktrace

java.lang.ClassCastException myapp.state.SimpleSearchString cannot be cast
to myapp.state.SimpleSearchString
Stack trace

   - myapp.components.search.Search._$read_simpleSearchString(Search.java
   )
   - myapp.components.search.Search.getSimpleSearchString(Search.java:79)
   - myapp.components.search.Search.onSuccess(Search.java:53)
   - myapp.components.search.Search.handleComponentEvent(Search.java)


This happens regardless of if I access simpleSearchString directly or with
the getter.
Any idead what causes this somewhat puzzling behaviour?

Regards,
Otho





> 2007/5/11, Juan Maya <ma...@gmail.com>:
> > i think u can only access ur ASOs in pages or components.  I am not sure
> > about it :S
> >
> > On 5/11/07, Eric Chatellier <ch...@codelutin.com> wrote:
> > >
> > > thanks, it' works
> > >
> > > I check if user is authenticated and if not redirect to loginForm
> > >
> > > but now I got a strange error using @ApplicationState
> > >
> > >    @ApplicationState
> > >    private SessionBean sessionBean;
> > >
> > > In this form, when I try to log the user sessionBean.setLogged(true),
> > > this excepion is thrown :
> > >
> > > org.package.test.web.tapestry.base.SessionBean cannot be cast to
> > > org.package.test.web.tapestry.base.SessionBean
> > >
> > > The cast done by tapestry seams good, so how this exception can be
> throw ?
> > >
> > >
> > > 2007/5/11, Juan Maya <ma...@gmail.com>:
> > > > Hi Eric,
> > > > i think the best way to do it is to contrib to the Request handler
> > > pipilene
> > > > (
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/request.html)
> > > > To contrib to a pipeline do it your AppModule:
> > > >
> > > >  public RequestFilter buildTimingFilter(final Log log) {
> > > >     return new RequestFilter() {
> > > >         public boolean service(Request request, Response response,
> > > >             RequestHandler handler) throws IOException {
> > > >         long startTime = System.currentTimeMillis();
> > > >         try {
> > > >             // The reponsibility of a filter is to invoke the
> > > >             // corresponding method
> > > >             // in the handler. When you chain multiple filters
> > > >             // together, each filter
> > > >             // received a handler that is a bridge to the next
> > > >             // filter.
> > > >             return handler.service(request, response);
> > > >
> > > >         } finally {
> > > >             long elapsed = System.currentTimeMillis() - startTime;
> > > >             log.info(String.format("Request time: %d ms",
> Long.valueOf
> > > > (elapsed)));
> > > >         }
> > > >         }
> > > >     };
> > > >     }
> > > >
> > > >
> > > >     /**
> > > >      * This is a contribution to the RequestHandler service
> > > configuration.
> > > >      * This is how we extend Tapestry using the timing filter. A
> common
> > > use
> > > >      * for this kind of filter is transaction management or
> security.
> > > >      */
> > > >     public void
> > > contributeRequestHandler(OrderedConfiguration<RequestFilter>
> > > > configuration, @InjectService("TimingFilter") RequestFilter filter)
> {
> > > >     // Each contribution to an ordered configuration has a name,
> When
> > > >     // necessary, you may
> > > >     // set constraints to precisely control the invocation order of
> the
> > > >     // contributed filter
> > > >     // within the pipeline.
> > > >     configuration.add("Timing", filter);
> > > >     }
> > > >
> > > >
> > > >
> > > > On 5/11/07, Eric Chatellier <ch...@codelutin.com> wrote:
> > > > >
> > > > > hi everyone
> > > > >
> > > > > I'm starting using Tapestry 5.0.4 and i'm tying to implement an
> > > > > authentication filter.
> > > > >
> > > > >
> > > > > In some tapestry 4 samples, code was :
> > > > >
> > > > > public abstract class AuthenticatedPage implements
> > > PageValidateListener {
> > > > >
> > > > >         public void pageValidate(PageEvent event) {
> > > > >
> > > > >                 if (!isSessionBeanExist() ||
> > > > > getSessionBean().getUid()==-1) {
> > > > >                         Login loginPage = (Login)getRequestCycle()
> > > > >
> > > > >                  .getPage("Login");
> > > > >
> > > > >                         loginPage.setCallback(new
> PageCallback(this));
> > > > >
> > > > >                         throw new
> PageRedirectException(loginPage);
> > > > >                 }
> > > > >         }
> > > > > }
> > > > >
> > > > > public class ProjectList extends AuthenticatedPage {
> > > > >   [...]
> > > > > }
> > > > >
> > > > > but i can't find the way to do it in tapestry 5.
> > > > >
> > > > > thanks in advance for help, and sorry for my bad english ;)
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > > > For additional commands, e-mail: users-help@tapestry.apache.org
> > > > >
> > > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 - Authentication filter

Posted by Marcus <mv...@gmail.com>.
Hi All,

We're using onActivate()

public abstract class ProtectedPage {
    @ApplicationState
    private Visit _visit;

    public Visit getVisit()  { return _visit; }

    public void setVisit(Visit _visit)   { this._visit = _visit; }

    Object onActivate()  {
        if (!_visit.isLogged())
           return "Login";    // Redireciona para a página de Login.

       return null;        // Retornando null ou true permite o acesso a
página.
    }
}


public class Portal extends ProtectedPage {

}


Marcus

RE: T5 - Authentication filter

Posted by Bret Gregory <br...@reged.com>.
That was it.  Thanks for the help!

-----Original Message-----
From: Davor Hrg [mailto:hrgdavor@gmail.com] 
Sent: Monday, July 16, 2007 2:27 AM
To: Tapestry users
Subject: Re: T5 - Authentication filter

it may be usefull,
please check that you havent put your ASO class in components package
or pages package (those classes get enhanced and can cause class cast
exceptions)

Davor Hrg

On 7/16/07, bmg125 <br...@reged.com> wrote:
>
>
> Otho did you ever find a solution to the the Class Cast Exception when
> using
> the @ApplicationState annotation?  I have read and reread the docs and
it
> seems like my code should work.  I am basically just trying to create
an
> ASO
> with the default persistence strategy and constructor.  So I am not
sure I
> understand why I am getting the class cast exception.
>
> -BGregory
>
>
>
> Otho wrote:
> >
> > Hi all!
> > Was there a solution to this really strange ClassCastException
already?
> >
> > I have the same problem in the following circumstances:
> >
> > public class Search extends BaseComponent
> > {
> >     @Component
> >     private Form simpleSearch;
> >
> >     @ApplicationState
> >     private SimpleSearchString simpleSearchString;
> >
> >     private String searchTerm; // wil be populated by the form;
> >
> >     /* Form Handler */
> >
> >     String onSuccess()
> >     {
> >         if (searchTerm == null)
> >             return null;
> >
> >
> >>>>>        getSimpleSearchString().setSearchTerm(searchTerm);
> >         return "ExtendedSearch";
> >     }
> >
> >     public SimpleSearchString getSimpleSearchString()
> >     {
> >         return simpleSearchString;
> >     }
> >
> >>>>> This line gives the following stacktrace
> >
> > java.lang.ClassCastException myapp.state.SimpleSearchString cannot
be
> cast
> > to myapp.state.SimpleSearchString
> > Stack trace
> >
> >    - myapp.components.search.Search._$read_simpleSearchString(
> Search.java
> >    )
> >    -
myapp.components.search.Search.getSimpleSearchString(Search.java
> :79)
> >    - myapp.components.search.Search.onSuccess(Search.java:53)
> >    -
myapp.components.search.Search.handleComponentEvent(Search.java)
> >
> >
> > This happens regardless of if I access simpleSearchString directly
or
> with
> > the getter.
> > Any idead what causes this somewhat puzzling behaviour?
> >
> > Regards,
> > Otho
> >
>
> --
> View this message in context:
>
http://www.nabble.com/T5---Authentication-filter-tf3726392.html#a1160794
6
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5 - Authentication filter

Posted by Davor Hrg <hr...@gmail.com>.
it may be usefull,
please check that you havent put your ASO class in components package
or pages package (those classes get enhanced and can cause class cast
exceptions)

Davor Hrg

On 7/16/07, bmg125 <br...@reged.com> wrote:
>
>
> Otho did you ever find a solution to the the Class Cast Exception when
> using
> the @ApplicationState annotation?  I have read and reread the docs and it
> seems like my code should work.  I am basically just trying to create an
> ASO
> with the default persistence strategy and constructor.  So I am not sure I
> understand why I am getting the class cast exception.
>
> -BGregory
>
>
>
> Otho wrote:
> >
> > Hi all!
> > Was there a solution to this really strange ClassCastException already?
> >
> > I have the same problem in the following circumstances:
> >
> > public class Search extends BaseComponent
> > {
> >     @Component
> >     private Form simpleSearch;
> >
> >     @ApplicationState
> >     private SimpleSearchString simpleSearchString;
> >
> >     private String searchTerm; // wil be populated by the form;
> >
> >     /* Form Handler */
> >
> >     String onSuccess()
> >     {
> >         if (searchTerm == null)
> >             return null;
> >
> >
> >>>>>        getSimpleSearchString().setSearchTerm(searchTerm);
> >         return "ExtendedSearch";
> >     }
> >
> >     public SimpleSearchString getSimpleSearchString()
> >     {
> >         return simpleSearchString;
> >     }
> >
> >>>>> This line gives the following stacktrace
> >
> > java.lang.ClassCastException myapp.state.SimpleSearchString cannot be
> cast
> > to myapp.state.SimpleSearchString
> > Stack trace
> >
> >    - myapp.components.search.Search._$read_simpleSearchString(
> Search.java
> >    )
> >    - myapp.components.search.Search.getSimpleSearchString(Search.java
> :79)
> >    - myapp.components.search.Search.onSuccess(Search.java:53)
> >    - myapp.components.search.Search.handleComponentEvent(Search.java)
> >
> >
> > This happens regardless of if I access simpleSearchString directly or
> with
> > the getter.
> > Any idead what causes this somewhat puzzling behaviour?
> >
> > Regards,
> > Otho
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5---Authentication-filter-tf3726392.html#a11607946
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 - Authentication filter

Posted by bmg125 <br...@reged.com>.
Otho did you ever find a solution to the the Class Cast Exception when using
the @ApplicationState annotation?  I have read and reread the docs and it
seems like my code should work.  I am basically just trying to create an ASO
with the default persistence strategy and constructor.  So I am not sure I
understand why I am getting the class cast exception.  

-BGregory



Otho wrote:
> 
> Hi all!
> Was there a solution to this really strange ClassCastException already?
> 
> I have the same problem in the following circumstances:
> 
> public class Search extends BaseComponent
> {
>     @Component
>     private Form simpleSearch;
> 
>     @ApplicationState
>     private SimpleSearchString simpleSearchString;
> 
>     private String searchTerm; // wil be populated by the form;
> 
>     /* Form Handler */
> 
>     String onSuccess()
>     {
>         if (searchTerm == null)
>             return null;
> 
> 
>>>>>        getSimpleSearchString().setSearchTerm(searchTerm);
>         return "ExtendedSearch";
>     }
> 
>     public SimpleSearchString getSimpleSearchString()
>     {
>         return simpleSearchString;
>     }
> 
>>>>> This line gives the following stacktrace
> 
> java.lang.ClassCastException myapp.state.SimpleSearchString cannot be cast
> to myapp.state.SimpleSearchString
> Stack trace
> 
>    - myapp.components.search.Search._$read_simpleSearchString(Search.java
>    )
>    - myapp.components.search.Search.getSimpleSearchString(Search.java:79)
>    - myapp.components.search.Search.onSuccess(Search.java:53)
>    - myapp.components.search.Search.handleComponentEvent(Search.java)
> 
> 
> This happens regardless of if I access simpleSearchString directly or with
> the getter.
> Any idead what causes this somewhat puzzling behaviour?
> 
> Regards,
> Otho
> 

-- 
View this message in context: http://www.nabble.com/T5---Authentication-filter-tf3726392.html#a11607946
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 - Authentication filter

Posted by Otho <ta...@googlemail.com>.
Hi all,
the ASO works fine if I instantiate it myself like

@ApplicationState
private SimpleSearchString simpleSearchString = new SimpleSearchString();

Without that the ApplicationStateHandler's "object" property is null and
this strange class cast exception is thrown.

>From the docs I thought that this instantiation should not be necessary?

Regards,
Otho


2007/6/23, Otho <ta...@googlemail.com>:
>
> Hi all!
> Was there a solution to this really strange ClassCastException already?
>
> I have the same problem in the following circumstances:
>
> public class Search extends BaseComponent
> {
>     @Component
>     private Form simpleSearch;
>
>     @ApplicationState
>     private SimpleSearchString simpleSearchString;
>
>     private String searchTerm; // wil be populated by the form;
>
>     /* Form Handler */
>
>     String onSuccess()
>     {
>         if (searchTerm == null)
>             return null;
>
>
> >>>>        getSimpleSearchString().setSearchTerm(searchTerm);
>         return "ExtendedSearch";
>     }
>
>     public SimpleSearchString getSimpleSearchString()
>     {
>         return simpleSearchString;
>     }
>
> >>>> This line gives the following stacktrace
>
> java.lang.ClassCastException myapp.state.SimpleSearchString cannot be cast
> to myapp.state.SimpleSearchString
> Stack trace
>
>    - myapp.components.search.Search._$read_simpleSearchString(
>    Search.java)
>    - myapp.components.search.Search.getSimpleSearchString(Search.java
>    :79)
>    - myapp.components.search.Search.onSuccess (Search.java:53)
>    - myapp.components.search.Search.handleComponentEvent(Search.java)
>
>
> This happens regardless of if I access simpleSearchString directly or with
> the getter.
> Any idead what causes this somewhat puzzling behaviour?
>
> Regards,
> Otho