You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jason Pyeron <jp...@pdinc.us> on 2014/10/27 14:20:07 UTC

RE: [struts-user] Re: struts2 json return null if involve hibernate or spring

> -----Original Message-----
> From: john lee 
> Sent: Monday, October 27, 2014 9:06
> 
> the delete itself has no problem if called it directly. 

(please try not to top post)

>       From: Lukasz Lenart <lu...@apache.org>
>  To: Struts Users Mailing List <us...@struts.apache.org> 
>  Sent: Monday, October 27, 2014 2:46 AM
>  Subject: Re: struts2 json return null if involve hibernate or spring
>    
> 2014-10-27 3:55 GMT+01:00 john lee <sh...@yahoo.com.invalid>:
> 
> 
> >  is hibernate dao manipulation could affect struts 2 json return?

In my expereince yes, regarding lazy loading and caching. But your code sample does not give enough detail to say if that is likely. What is the status of the Hibernate/JPA session at the time of the View rendering? 

> > 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...

What is the Hibernate code here?

Do you have the same problems in your JSP Views?

> >              */
> >
> >              deleted=true;
> >              return "json-data";
> >      }
> > }
> > CartManagerImpl.javaimport 
> org.apache.struts2.ServletActionContext;import 
> org.springframework.web.context.WebApplicationContext;
> > import 
> org.springframework.web.context.support.WebApplicationContextU
> tils;public class CartManagerImpl  {
> >    dao_delete ....
> > }
> 
> Maybe you have some exception here or some other problem when deleting
> that item?

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00. 


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


Re: [struts-user] Re: struts2 json return null if involve hibernate or spring

Posted by john lee <sh...@yahoo.com.INVALID>.
What is the status of the Hibernate/JPA session at the time of the View rendering? 
i just use the following session approach       in the application.xml          <bean id="cartmgr" class="CartManagerImpl" scope="prototype">                  <property name="cartDao" ref="cartDao"/>          </bean>
 in the CartManagerImpl.java  public class CartManagerImpl implements CartManager  {
    CartDao cartDao;    public void setCartDao(CartDao cartDao) { this.cartDao=cartDao; }           public void removeSingle(Cartitem item) throws Exception { cartDao.deleteSingle(item); }
  

      From: Jason Pyeron <jp...@pdinc.us>
 To: 'Struts Users Mailing List' <us...@struts.apache.org> 
 Sent: Monday, October 27, 2014 8:20 AM
 Subject: RE: [struts-user] Re: struts2 json return null if involve hibernate or spring
   
> -----Original Message-----
> From: john lee 
> Sent: Monday, October 27, 2014 9:06
> 
> the delete itself has no problem if called it directly. 

(please try not to top post)

>      From: Lukasz Lenart <lu...@apache.org>
>  To: Struts Users Mailing List <us...@struts.apache.org> 
>  Sent: Monday, October 27, 2014 2:46 AM
>  Subject: Re: struts2 json return null if involve hibernate or spring
>    
> 2014-10-27 3:55 GMT+01:00 john lee <sh...@yahoo.com.invalid>:
> 
> 
> >  is hibernate dao manipulation could affect struts 2 json return?

In my expereince yes, regarding lazy loading and caching. But your code sample does not give enough detail to say if that is likely. What is the status of the Hibernate/JPA session at the time of the View rendering? 

> > 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...

What is the Hibernate code here?

Do you have the same problems in your JSP Views?

> >              */
> >
> >              deleted=true;
> >              return "json-data";
> >      }
> > }
> > CartManagerImpl.javaimport 
> org.apache.struts2.ServletActionContext;import 
> org.springframework.web.context.WebApplicationContext;
> > import 
> org.springframework.web.context.support.WebApplicationContextU
> tils;public class CartManagerImpl  {
> >    dao_delete ....
> > }
> 
> Maybe you have some exception here or some other problem when deleting
> that item?

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                              -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218  -
-                                                              -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00. 




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