简体   繁体   中英

Cross-form validation issue tapestry

I really new in Java....i work some research in java using tool Tapestry framework... I have some problem with exception when i calling @Component "Form"...tapestry throws me exception :

Embedded component(s) loginForm are defined within component class com.fit.pages.Login (or a super-class of Login), but are not present in the component template (classpath:com/fit/pages/Login.tml).

context eventType

activate

org.apache.tapestry5.ioc.internal.OperationException

Embedded component(s) loginForm are defined within component class com.fit.pages.Login (or a super-class of Login), but are not present in the component template (classpath:com/fit/pages/Login.tml).

trace

    **Triggering event 'activate' on Index
    Constructing instance of page class com.fit.pages.Login
    Creating ComponentAssembler for com.fit.pages.Login**

my code looks something like this

public class Login {

private String userName;

@Property
private String password;

@Inject
@Property
private Users users;

@SessionState
private User user;

@Component(id="loginForm")
private Form loginForm;

@Inject
private Messages messages;

public String getUserName() {
    return userName;
}



public void setUserName(String userName) {
    this.userName = userName;
}


void onValidate(){
    User authenticatedUser = Security.authenticate(userName, password, users);
    if(authenticatedUser != null){
        user = authenticatedUser;
    }else{
        loginForm.recordError(messages.get("authentication-failed"));
    }
}



@OnEvent
Object onSubmit(){
    System.out.println("form was submited");
    Class nextPage = null;
    User authenticatedUser = Security.authenticate(userName, password, users);
    if(authenticatedUser != null){
        user = authenticatedUser;
        nextPage = Index.class;
    } else {

    nextPage = Registration.class;
    }
    return nextPage;
}

and code in login.tml :

Please log in:

    <t:form id="loginForm">
    <table>
            <tr>
                <td>
                <t:label t:for="userName"/>:
                </td>
                <td>
                    <input type="text" t:type="textfield"  t:id="userName" 
                    t:value="userName" t:validate="required"/>
                </td>
            </tr>
            <tr> 
                <td>
                <t:label t:for="password"/>:
                </td>
                <td>
                    <input type="text" t:type="passwordfield"  t:id="password" 
                    t:value="password" t:validate="required"/>
                    </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="Log In"/>
                </td>
            </tr>               
    </table>    
    </t:form>

replace

<t:form id="loginForm">

with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM