2010-02-24 24 views

Trả lời

2

Bạn có thể sử dụng xác thực 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

Ý của bạn là '

+0

Không, nó không phải là lỗi đánh máy, đó là thẻ Dojo Strutses. Đối với xác nhận struts tôi hy vọng bạn sẽ nhận được một asnwer. – Trick

4

Bạn có thể sử dụng một validator biểu. Nếu bạn đang xác thực qua XML, bạn nên có một cái gì đó như:

<validators> 

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

</validators> 

Xem http://struts.apache.org/2.2.1/docs/validation.html để biết thêm thông tin.

Các vấn đề liên quan