2016-03-20 34 views
0

JSP'de, JSTL'nin değerine göre bir JSP işlevi çağırıyorum. JS içindeki (JSTL içinde) uyarı ifadesini görüyorum, fakat JQuery'yi değil. Neden? JS/JQuery işlevi JSTL içinde neden çalışmıyor?

<c:set var = "error" value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> 
<c:choose>     

    <c:when test="${error=='not unregistered'}"> 
      <script type="text/javascript"> 
       alert("Hi"); 
       openSignUp(); 
      </script>                    
    </c:when> 
    <c:otherwise> 
     <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />            
    </c:otherwise>          
</c:choose>      
<c:remove var = "SPRING_SECURITY_LAST_EXCEPTION" scope = "session" /> 

<script> 
    function openSignUp(){ 
     $('#signUp_dialog').dialog({ 
      width:350, 
      open: function(event, ui) { 
      $(".ui-button-text").remove(); 
      $(".ui-dialog-title").css("margin-right","275px"); 
      } 
     });      
    } 

</script> 

Ben JSTL ait komut dosyası etiketlerinin içinde doğrudan JS işlevi içinde kod koyarak, hem de aşağıdaki çalıştı. Hala hayır şans.

<c:set var = "error" value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> 
<c:choose>     
    <c:when test="${error=='not unregistered'}"> 
     <script type="text/javascript" src="<c:url value="/resources/scripts/jquery-ui-1.11.4/external/jquery/jquery.js" />"> 
     $(document).ready(function() { 
      $('#signUp_dialog').dialog({ 

       width:350, 
       open: function(event, ui) { 
        alert("hi"); 
        $(".ui-button-text").remove(); 
       $(".ui-dialog-title").css("margin-right","275px"); 
       } 
      });  
     });  
     </script>                    
    </c:when> 
    <c:otherwise> 
     <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />            
    </c:otherwise>          
</c:choose>      
<c:remove var = "SPRING_SECURITY_LAST_EXCEPTION" scope = "session" /> 

Lütfen bana yardım edin. Teşekkürler.

+0

"signUp_dialog" öğesi, DOM işaret eden * sonra * görünürse, kodunuz öğeyi bulamayacağından çalışmayacaktır. – Pointy

cevap

0

Javascript kodunuz (düz java komut dosyası veya jquery olsun) sayfa yüklemesi sırasında tetiklenmelidir (tüm java/jsp/jstl işlemleri tamamlandıktan sonra). Bu yüzden, JSP sayfanızın sonunda (tüm öğeler işlendikten sonra) bir komut satırında openSignUp'ı çağırın.

...JSP page 
<script> 
//openSignUp definition here 

//check the condition first 
if(${error} == 'not unregistered'})//this should translate to either true or false 
{ 
    openSignUp();//if the conditon is true, call the dialog 
} 
</script> 
0

JQuery ile ilgili dosyaları içe aktardınız mı? Ayrıca, sayfayı yükledikten sonra görünümü kontrol et.

+0

Bu bir yorum cevap olmamalıdır. –