2011-05-18 61 views
3

我真的是新的Java ....我在使用工具Tapestry框架在java中进行一些研究... 当我调用@Component“Form”时,异常中有一些问题... tapestry抛出异常:跨格式验证问题挂毯

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

上下文 EVENTTYPE

激活

org.apache.tapestry5.ioc.internal.OperationException

嵌入式成分(S)被登录表单组件类com.fit.pages中定义的。登录(或超级的登录),但不在组件模板(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** 

我的代码看起来是这样的

公共类登录{

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

是否使用'进口org.apache.tapestry.form.Form'更换? – sfrj 2011-05-18 11:17:33

+0

您是否试过'' – sfrj 2011-05-18 11:21:09

+0

我可以问一下您使用Security.authenticate(...)导入了什么? – 2015-04-05 14:44:53

回答

2

<t:form id="loginForm"> 

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

嗨,它的作品非常感谢你:) – dusmanka 2011-05-18 11:28:07