2012-10-22 39 views
1

我們有一個問題在我們的登錄頁面有一個使用post方法的表單,問題是有時候post參數對於服務器來說是空的,但它們不爲空。表單驗證器的行爲與參數沒有輸入一樣。我把我的表單代碼放在下面。你有任何想法或直覺?Wicket表單提交數據丟失

protected class LoginForm extends OurForm { 

    private static final long serialVersionUID = -5813819309808445973L; 

    public LoginForm(String id) { 
     super(id); 

     setDefaultModel(new CompoundPropertyModel<Map<Object , Object>>(iMap)); 
     TextField<String> userId=new TextField<String>("USERCODE" , String.class); 
     userId.setOutputMarkupId(true); 
     userId.setRequired(true); 
     add(userId); 

     PasswordTextField password = new PasswordTextField("USERPASSWORD"); 
     password.setOutputMarkupId(true); 
     password.setRequired(true); 
     add(password); 

     add(new SubmitLink("SUBMIT")); 
    } 

通過檢票口生成的HTML形式的代碼:

<form autocomplete="off" id="id2" method="post" action=";jsessionid=989511050F24C577A23CF7CC55BC9757.salacakEUPT?x=UYCQLoTt3sXylAFd5u7DPGpiOKN9Mx4oErlMwLtbLndItHXg9LDIrg"><div style="width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden"><input type="hidden" name="id2_hf_0" id="id2_hf_0" /></div> 
<table width="100%"> 
<tr><td colspan="3"><h2>&nbsp; </h2></td></tr> 
<tr><td width="10%">&nbsp;</td> 
<td width="80%"> 
<table width="100%"> 
<tr><td colspan="2" height="100">&nbsp;</td></tr> 
<tr> 
<td align="right" width="50%"><label class="label" >Kullanıcı Kodu</label></td> 
<td align="left" width="50%"><input type="text" value="" name="USERCODE" id="id3"/></td> 
</tr> 
<tr> 
<td align="right"><label class="label" >Şifre</label></td> 
<td align="left" ><input type="password" value="" name="USERPASSWORD" id="id4"/></td> 
</tr> 
<tr><td colspan="2" height="20">&nbsp;</td></tr> 
<tr><td colspan="2" align="center"><input type="submit" id="id5" onclick="var wcall=euptWicketSubmitFormById('id2', ';jsessionid=989511050F24C577A23CF7CC55BC9757.salacakEUPT?x=UYCQLoTt3sXylAFd5u7DPIvNsZm6zLH4Nn8IO6OcpRl09M**bsF1rsqDb-hhJWazVdFfqhn-IWmQiM30HCroAnex3YAslQLnMwTnZBT5fO6Cuav6A95RGA', 'SUBMIT' ,function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$$(this)&amp;&amp;Wicket.$$('id2')}.bind(this));;; return false;" submitlink="true" value="Giriş"/></td></tr> 
<tr><td colspan="2" height="100">&nbsp;</td></tr> 
</table> 
</td> 
<td width="10%"></td></tr></table> 
</form> 

注:有時會出現此問題不是每次。

回答

0

FWIK,窗體組件沒有得到處理,直到形式的onSubmit()方法被調用。我通常在這一步沿線的財產以後叫我堅持數據:

@Override 
    protected void onSubmit() { 
     Item item = (Item) getModelObject(); 
     dao.storeItem(item); 
     setResponsePage(page); 
    } 

我不熟悉SubmitLink("id"),所以我不能告訴你爲什麼不工作。只要您的OurForm類具有與org.apache.wicket.markup.html.form.Form相同的行爲,上述方法應該可以工作。在調用onSubmit()方法之前,您的驗證也不應檢查組件輸入。另外,seba是正確的,您應該在您的TextFields的構造函數中使用Model或PropertyModel。

0

模型屬於表單在哪裏?我的意思是在Wicket中你基本上總是和Models一起工作,你永遠不會訪問原始的Post數據。在您的示例窗體中根本沒有定義模型。這很奇怪。我會建議使用模型。

例如,這是我們的SignInForm: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/pages/auth/

它指定使用PropertyModel的PARAMS。

塞巴斯蒂安

+0

我們在代碼中使用compoundpropertymodel這行代碼就是這樣。 setDefaultModel(new CompoundPropertyModel >(iMap)); –

+0

我們所有的頁面都使用這個模型,我們通過地圖達到組件值 –

+0

你的代碼片段並不顯示你如何閱讀表單處理的結果。 –