跨表单验证问题挂毯

发布于 2024-11-08 15:25:29 字数 2799 浏览 0 评论 0原文

我对 Java 真的很陌生......我使用 Tapestry 框架工具对 Java 进行了一些研究...... 当我调用@Component“Form”时,我遇到一些异常问题... Tapestry 抛出异常:

嵌入式组件loginForm在组件类com.fit.pages.Login(或超类)中定义Login),但不存在于组件模板 (classpath:com/fit/pages/Login.tml) 中。

eventType

activate

org.apache.tapestry5.ioc.internal.OperationException

嵌入式组件 loginForm 在组件类 com.fit.pages.Login (或 Login 的超类)中定义,但不存在于组件模板(classpath:com/fit/pages/Login.tml)。

跟踪

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

我的代码看起来像这样

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

和 login.tml 中的代码:

请登录:

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀梦 2024-11-15 15:25:29

替换

<t:form id="loginForm">

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

replace

<t:form id="loginForm">

with

<t:form t:id="loginForm">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文