2010-02-24 13 views

risposta

2

Potrebbe essere possibile utilizzare la convalida 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

Intendevi '

+0

No, non è un errore di battitura, è il tag Dojo di Strutses. Per la convalida delle sostegni spero che ne riceverai una. – Trick

4

probabilmente si può utilizzare un validatore espressione. Se stai convalidare tramite XML, si dovrebbe avere qualcosa di simile:

<validators> 

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

</validators> 

Vedi http://struts.apache.org/2.2.1/docs/validation.html per maggiori informazioni.

Problemi correlati