struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: struts2 json return null if involve hibernate or spring
Date Mon, 27 Oct 2014 07:46:29 GMT
2014-10-27 3:55 GMT+01:00 john lee <sh_thorn_bird@yahoo.com.invalid>:
>  is hibernate dao manipulation could affect struts 2 json return?
> or spring framework could affect struts2 json return?
> my program's struts2 json execution is success if not involve dao or spring call.
> but if involve hibernate/spring/dao manipulation, then json return is null and not returned.
> struts.xml<package name="default" extends="json-default">     ...     <action
name="cart-del" class="CartAction" method="del">
>                     <result name="json-data" type="json"></result>
>
>      </action>
> </package>
> Cart.jsp <sj:head jqueryui="true" jquerytheme="%{theme}" loadFromGoogle="%{google}"
ajaxhistory="%{ajaxhistory}" defaultIndicator="myDefaultIndicator"/>
>
>  <%@ taglib prefix="s" uri="/struts-tags" %>
>  <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <script type="text/javascript">
>     function delItem(sn) {
>                 alert("here10, sn="+sn);
>                 $.post('cart-del.action', {partid: sn}, function(data) {
>                         alert("here20, data.deleted="+data.deleted);
>                         if (data.deleted) {
>                                 alert("here30 - deleted");
>                                 $('#tr_' + sn).remove();
>                                 }                               }
>                         else
>                                 alert("here40 - not delete");
>                 });
>         }
> </scipt><s:iterator value="#session.cartitems">
>    <tr id="tr_${j_part_id}">
>        <td><input type="checkbox" onclick="delItem('${j_part_id }')" /></td>
>        <td>${part.pid}<input type="hidden" name="partids" value="${j_part_id}"
/>>/td>
>    </tr>
> </s:iterator>
> CartAction.java
>   public class AcctAction extends ActionSupport {
>      private String partid;
>      private boolean deleted;
>      public void setPartid(String partid) { this.partid=partid.trim(); }
>      public String getPartid() { return partid; }
>      public boolean getDeleted() { return deleted; }     public String del() throws Exception
{
>               /* problem is:
>                   if enable following business dao logic to delete item from database,
the item is deleted,
>                   and this is proved from querying database,
>                   but deleted variable always 'not delete in the Cart.jsp alert statement.
>                   without business logic, then deleted can always return true;
>
>               */
>               /*
>                CartManagerImpl  cartmgr;
>                cartmgr.dao_delete...
>               */
>
>               deleted=true;
>               return "json-data";
>      }
> }
> CartManagerImpl.javaimport org.apache.struts2.ServletActionContext;import org.springframework.web.context.WebApplicationContext;
> import org.springframework.web.context.support.WebApplicationContextUtils;public class
CartManagerImpl  {
>     dao_delete ....
> }

Maybe you have some exception here or some other problem when deleting
that item?


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Mime
View raw message