2010-02-24 23 views

Odpowiedz

2

Możliwe, że możesz użyć sprawdzania poprawności JS.

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

Czy chodziło Ci o '

+0

Nie, to nie jest literówka, to tag Strutses Dojo. Do sprawdzania poprawności kolumn mam nadzieję, że dostaniesz asnwer. – Trick

4

Prawdopodobnie można używać walidatora ekspresyjny. Jeśli walidacji poprzez XML, trzeba mieć coś takiego:

<validators> 

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

</validators> 

Zobacz http://struts.apache.org/2.2.1/docs/validation.html aby uzyskać więcej informacji.

Powiązane problemy