2010-02-24 5 views

cevap

2

JS doğrulamasını kullanabilirsiniz.

JSP:

<s:checkbox id="other" name="other" /> 
<s:textfield id="otherDetails" name="otherDetails"></s:textfield> 

<sx:submit 
      id="button_submit" 
      name="button_submit" 
      onclick="return checkOther();" /> 

JS:

function checkOther() { 
    if(document.getElementById('other').checked == true) { 
     if(document.getElementyById('otherDetails').value.length == 0) { 
      //you should trim the value 
      alert("Insert other details"); 
      return false; 
     } 
    } 

    return true; 
} 
+0

Bunu mu demek istediniz:

+0

Hayır, bu bir yazım hatası değil, Strutses Dojo etiketi. Struts doğrulama için umarım bir asnwer elde edersiniz. – Trick

4

Muhtemelen bir ifade doğrulayıcı kullanabilirsiniz.

<validators> 

    <validator type="expression"> 
    <param name="expression">(other && (otherDetails!=null && otherDetails.trim()!=""))</param> 
    <message>You must provide other details.</message> 
    </validator> 

</validators> 

fazla bilgi için http://struts.apache.org/2.2.1/docs/validation.html bakınız: XML yoluyla doğrulama ediyorsanız, böyle bir şey olmalı.