You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John <jo...@quivinco.com> on 2012/10/23 19:40:48 UTC

Login page problems

I did a T4 project ages ago and now learning T5.

I just want to build a working login page and copied the code snippets here http://tapestry.apache.org/forms-and-validation.html and added them to the quickstart application - my versions appear below.

When I navigate to the Login page it returns:
Embedded component(s) form are defined within component class com.epulse.tapestrydemo.pages.Login (or a super-class of Login), but are not present in the component template (classpath:com/epulse/tapestrydemo/pages/Login.tml).

Has anyone a simple login page example that works, or can help with the above?

John



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.epulse.tapestrydemo.pages;

import com.epulse.tapestrydemo.security.UserAuthenticator;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PasswordField;
import org.apache.tapestry5.ioc.annotations.Inject;

public class Login
{
    @Persist
    @Property
    private String userName;

    @Property
    private String password;

    @Inject
    private UserAuthenticator authenticator;

    @InjectComponent
    private PasswordField passwordField;

    @Component
    private Form form;

    /**
     * Do the cross-field validation
     */
    void onValidateFromForm()
    {
        if (!authenticator.isValid(userName, password))
        {
            // record an error, and thereby prevent Tapestry from emitting a "success" event
            form.recordError(passwordField, "Invalid user name or password.");
        }
    }

    /**
     * Validation passed, so we'll go to the "PostLogin" page
     */
    Object onSuccess()
    {
        return About.class;
    }
}


<html t:type="layout" title="Contact com.epulse"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
      xmlns:p="tapestry:parameter">

        <h1>Please Login</h1>

        <form t:type="form" t:id="loginForm">

            <t:errors/>

            <t:label for="userName"/>:
            <input t:type="TextField" t:id="userName" t:validate="required,minlength=3" size="30"/>
            <br/>
            <t:label for="password"/>:
            <input t:type="PasswordField" t:id="password" t:validate="required,minlength=3" size="30"/>
            <br/>
            <input type="submit" value="Login"/>
        </form>

</html>

Re: Login page problems

Posted by Cezary Biernacki <ce...@gmail.com>.
Hi,
in your Java class you have
    @Component
    private Form form;

and in template:
        <form t:type="form" t:id="loginForm">

If you don't provide a component id is argument to @Component, Tapestry
uses field's name as the id. You need to do one of following:

   - change field name to loginForm,
   - or add "loginForm" as argument to @Component.
   - or change t:id in your template to "form"

In this case I would also recommend to use @InjectComponent instead of
@Component, e.g.:

    @InjectComponent("loginForm")
    private Form form;

Best regards
Cezary

On Tue, Oct 23, 2012 at 7:40 PM, John <jo...@quivinco.com> wrote:

> I did a T4 project ages ago and now learning T5.
>
> I just want to build a working login page and copied the code snippets
> here http://tapestry.apache.org/forms-and-validation.html and added them
> to the quickstart application - my versions appear below.
>
> When I navigate to the Login page it returns:
> Embedded component(s) form are defined within component class
> com.epulse.tapestrydemo.pages.Login (or a super-class of Login), but are
> not present in the component template
> (classpath:com/epulse/tapestrydemo/pages/Login.tml).
>
> Has anyone a simple login page example that works, or can help with the
> above?
>
> John
>
>
>
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package com.epulse.tapestrydemo.pages;
>
> import com.epulse.tapestrydemo.security.UserAuthenticator;
> import org.apache.tapestry5.annotations.Component;
> import org.apache.tapestry5.annotations.InjectComponent;
> import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.corelib.components.Form;
> import org.apache.tapestry5.corelib.components.PasswordField;
> import org.apache.tapestry5.ioc.annotations.Inject;
>
> public class Login
> {
>     @Persist
>     @Property
>     private String userName;
>
>     @Property
>     private String password;
>
>     @Inject
>     private UserAuthenticator authenticator;
>
>     @InjectComponent
>     private PasswordField passwordField;
>
>     @Component
>     private Form form;
>
>     /**
>      * Do the cross-field validation
>      */
>     void onValidateFromForm()
>     {
>         if (!authenticator.isValid(userName, password))
>         {
>             // record an error, and thereby prevent Tapestry from emitting
> a "success" event
>             form.recordError(passwordField, "Invalid user name or
> password.");
>         }
>     }
>
>     /**
>      * Validation passed, so we'll go to the "PostLogin" page
>      */
>     Object onSuccess()
>     {
>         return About.class;
>     }
> }
>
>
> <html t:type="layout" title="Contact com.epulse"
>       xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>       xmlns:p="tapestry:parameter">
>
>         <h1>Please Login</h1>
>
>         <form t:type="form" t:id="loginForm">
>
>             <t:errors/>
>
>             <t:label for="userName"/>:
>             <input t:type="TextField" t:id="userName"
> t:validate="required,minlength=3" size="30"/>
>             <br/>
>             <t:label for="password"/>:
>             <input t:type="PasswordField" t:id="password"
> t:validate="required,minlength=3" size="30"/>
>             <br/>
>             <input type="submit" value="Login"/>
>         </form>
>
> </html>

Re: Login page problems

Posted by Shing Hing Man <ma...@yahoo.com>.
Instead of 

  @Component
    private Form form;



pleases try 

@InjectComponent(value="loginForm")

private Form form;

The difference bewteen @Component and @InjectComponent is explained on the following page. 

http://tapestry.apache.org/injection-faq.html


Shing 



________________________________
 From: John <jo...@quivinco.com>
To: users@tapestry.apache.org 
Sent: Tuesday, October 23, 2012 6:40 PM
Subject: Login page problems
 
I did a T4 project ages ago and now learning T5.

I just want to build a working login page and copied the code snippets here http://tapestry.apache.org/forms-and-validation.html and added them to the quickstart application - my versions appear below.

When I navigate to the Login page it returns:
Embedded component(s) form are defined within component class com.epulse.tapestrydemo.pages.Login (or a super-class of Login), but are not present in the component template (classpath:com/epulse/tapestrydemo/pages/Login.tml).

Has anyone a simple login page example that works, or can help with the above?

John



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.epulse.tapestrydemo.pages;

import com.epulse.tapestrydemo.security.UserAuthenticator;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PasswordField;
import org.apache.tapestry5.ioc.annotations.Inject;

public class Login
{
    @Persist
    @Property
    private String userName;

    @Property
    private String password;

    @Inject
    private UserAuthenticator authenticator;

    @InjectComponent
    private PasswordField passwordField;

    @Component
    private Form form;

    /**
     * Do the cross-field validation
     */
    void onValidateFromForm()
    {
        if (!authenticator.isValid(userName, password))
        {
            // record an error, and thereby prevent Tapestry from emitting a "success" event
            form.recordError(passwordField, "Invalid user name or password.");
        }
    }

    /**
     * Validation passed, so we'll go to the "PostLogin" page
     */
    Object onSuccess()
    {
        return About.class;
    }
}


<html t:type="layout" title="Contact com.epulse"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
      xmlns:p="tapestry:parameter">

        <h1>Please Login</h1>

        <form t:type="form" t:id="loginForm">

            <t:errors/>

            <t:label for="userName"/>:
            <input t:type="TextField" t:id="userName" t:validate="required,minlength=3" size="30"/>
            <br/>
            <t:label for="password"/>:
            <input t:type="PasswordField" t:id="password" t:validate="required,minlength=3" size="30"/>
            <br/>
            <input type="submit" value="Login"/>
        </form>

</html>

Re: Login page problems

Posted by Alex Kotchnev <ak...@gmail.com>.
John,
   your template defines the password component with an id of 'password',
whereas the class uses passwordField (the field name in the class is by
default the same as the id of the component in the template).

Cheers,

Alex K

On Tue, Oct 23, 2012 at 1:40 PM, John <jo...@quivinco.com> wrote:

> I did a T4 project ages ago and now learning T5.
>
> I just want to build a working login page and copied the code snippets
> here http://tapestry.apache.org/forms-and-validation.html and added them
> to the quickstart application - my versions appear below.
>
> When I navigate to the Login page it returns:
> Embedded component(s) form are defined within component class
> com.epulse.tapestrydemo.pages.Login (or a super-class of Login), but are
> not present in the component template
> (classpath:com/epulse/tapestrydemo/pages/Login.tml).
>
> Has anyone a simple login page example that works, or can help with the
> above?
>
> John
>
>
>
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package com.epulse.tapestrydemo.pages;
>
> import com.epulse.tapestrydemo.security.UserAuthenticator;
> import org.apache.tapestry5.annotations.Component;
> import org.apache.tapestry5.annotations.InjectComponent;
> import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.corelib.components.Form;
> import org.apache.tapestry5.corelib.components.PasswordField;
> import org.apache.tapestry5.ioc.annotations.Inject;
>
> public class Login
> {
>     @Persist
>     @Property
>     private String userName;
>
>     @Property
>     private String password;
>
>     @Inject
>     private UserAuthenticator authenticator;
>
>     @InjectComponent
>     private PasswordField passwordField;
>
>     @Component
>     private Form form;
>
>     /**
>      * Do the cross-field validation
>      */
>     void onValidateFromForm()
>     {
>         if (!authenticator.isValid(userName, password))
>         {
>             // record an error, and thereby prevent Tapestry from emitting
> a "success" event
>             form.recordError(passwordField, "Invalid user name or
> password.");
>         }
>     }
>
>     /**
>      * Validation passed, so we'll go to the "PostLogin" page
>      */
>     Object onSuccess()
>     {
>         return About.class;
>     }
> }
>
>
> <html t:type="layout" title="Contact com.epulse"
>       xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>       xmlns:p="tapestry:parameter">
>
>         <h1>Please Login</h1>
>
>         <form t:type="form" t:id="loginForm">
>
>             <t:errors/>
>
>             <t:label for="userName"/>:
>             <input t:type="TextField" t:id="userName"
> t:validate="required,minlength=3" size="30"/>
>             <br/>
>             <t:label for="password"/>:
>             <input t:type="PasswordField" t:id="password"
> t:validate="required,minlength=3" size="30"/>
>             <br/>
>             <input type="submit" value="Login"/>
>         </form>
>
> </html>