2015-09-16 20 views
0

我有一個電話號碼組件,我試圖驗證,但由於某種原因,我無法獲取條形碼驗證錯誤,以顯示在表單上的電話號碼字段。如果我在窗體的以外顯示標籤,則會顯示錯誤,但它們不會附加到該字段。沒有出現在表單中的文本字段上的條紋錯誤

<e:declare-component name="PhoneNumberForm" css="true" js="true"> 
    <stripes:errors /> <%-- This tag displays errors --%> 
    <e:sslform id="submit-phone-number-form" action="${componentContext.action}"> 
     <div class="phone-wrapper"> 
     <stripes:text name="phoneNumber" id="phoneNumber" class="TextInput" /> 
     <stripes:errors field="phoneNumber" /> <%-- This tag DOES NOT display errors --%> 
     </div> 
     ... 
    </e:sslform> 
</e:declare-component> 

表單提交給擴展ActionBean並實現ValidationErrorHandler的java類。我發現驗證方法被調用,並且驗證錯誤不是空的(它包含電話號碼驗證錯誤)。

需要注意的事項:當我更改表單以提交給beanclass而不是action時,錯誤字段顯示正確;然而,這不是我的解決方案,因爲這個組件在代碼庫的其他地方使用。 beanclass和action之間有什麼不同?

任何想法爲什麼?謝謝!

回答

0

stripes:error標籤嵌套在stripes:form標籤中時,顯示的錯誤將只會是發佈表單後產生的錯誤。相反地​​,可以說因爲沒有包含stripes:form,所以不清楚從哪個操作中得到電話號碼驗證錯誤。

你可以嘗試提供一個action屬性爲stripes:errors標籤:

<stripes:errors field="phoneNumber" action="${componentContext.action}"/> 

只是告訴條紋從形式行動必須得到該錯誤消息。

我從來沒有嘗試過這個,但它值得一試。

相關問題