On 07/27/2011 01:55 AM, Łukasz Lenart wrote:
2011/7/26 Emi Lu<em...@encs.concordia.ca>:
Did you try to call check_search_oprProcessAction.action directly ?
And maybe it's better to JSON plugin instead of home made protocol ?

I was thinking about JSON result plus jQuery.

For people have similar questions, my solution for now based on ajax + jQuery is:
=========================================================================
(1) In global tile template.jsp, added
   <div id="ajax_error_div" align="left">

   </div>


(2) In script.js, defined:
==============================
function ajax_check(url)
{
   var xmlhttp;
   var str = $("form").serialize(); //http://api.jquery.com/serialize/
   var tmp_str = "";
   if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
   }
   else
   {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   xmlhttp.onreadystatechange=function()
   {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
document.getElementById("ajax_error_div").innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.open("POST", url, false);

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   xmlhttp.send(str);
   var str = document.getElementById("ajax_error_div").innerHTML;
   if(str == null || str.trim() == "")
   {
      return true;
   }
   return false;
}


(3) main_display.jsp
=======================
<s:submit value="Search"
          theme="simple"
          onclick="return ajax_check('ajax_checkProcessAction')"
          action="searchProcessAction" />

(4) struts.xml
=================
    <action name="*ProcessAction"  method="{1}" class="ProcessAction">
      <result name="success" type="tiles">browse_main_page</result>
      <result name="error"   type="tiles">browse_main_page</result>
      <result name="ajax_check" >
            /WEB-INF/pages/errorinfo/ajax_error_check.jsp
     </result>
   </action>


(5) ajax_error_check.jsp
==========================
<%@ taglib prefix="s"     uri="/struts-tags"                       %>
   <s:if test="hasActionMessages()">
      <center>
      <div id="action_message_div"
style="width: 700px; border:thin solid black; background-color:#C5D1C0; padding-left: 10px; margin-bottom: 5px; "
           align="left">
                   <s:iterator value="actionMessages">
              <li>
                 <B><s:property escape="false" /> </B>
              </li>
                   </s:iterator>
      </div>
      </center>
   </s:if>


   <s:if test="hasActionErrors()">
     <center>
<div align="left" style="width: 700px; border:thin solid black; background-color:#D0CCAE; padding-left: 10px; margin-bottom: 5px">
         <s:iterator value="actionErrors">
         <li>
            <B><s:property escape="false" /> </B>
         </li>
         </s:iterator>
      </div>
      </center>
   </s:if>


Thank you for all inputs!

Emi

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to