You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by shekhar16 <sh...@gmail.com> on 2011/03/05 14:59:28 UTC
display data of action class on jsp in struts2
i m new to struts2,rest plugin and i m tring to retrieve data from database
through jpa and display it on jsp.
my action class successfully running and retrieving the data but unable to
show it on my jsp page.so if any body have idea about it please help me
my action class is
[code]
package com.action;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.struts2.convention.annotation.*;
import org.apache.struts2.rest.DefaultHttpHeaders;
import com.opensymphony.xwork2.ActionSupport;
@ParentPackage(value="default")
@Namespace("/")
@ResultPath(value="/")
public class noOfUsers extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String firstname;
List myList;
private String user;
@SuppressWarnings("unchecked")
@Action(value="usersn",results={
@Result(name="create",type="tiles",location="users")
})
public static DefaultHttpHeaders create(){
EntityManagerFactory emf=Persistence.createEntityManagerFactory("tujpa");
EntityManager em=emf.createEntityManager();
EntityTransaction entr=em.getTransaction();
entr.begin();
Query query=em.createQuery("select u.firstname from User u ");
List myList=query.getResultList();
System.out.println(myList);
entr.commit();
em.close();
return new DefaultHttpHeaders("create");
}
public List getMyList(){
return myList;
}
}
[/code ]
thanks in advance
--
View this message in context: http://old.nabble.com/display-data-of-action-class-on-jsp-in-struts2-tp31075171p31075171.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: display data of action class on jsp in struts2
Posted by "SACHIN :)" <mi...@hotmail.com>.
Your myList instance variable is not initialized with the data you want to display.
> Date: Sat, 5 Mar 2011 05:59:28 -0800
> From: shekharlaad16@gmail.com
> To: user@struts.apache.org
> Subject: display data of action class on jsp in struts2
>
>
> i m new to struts2,rest plugin and i m tring to retrieve data from database
> through jpa and display it on jsp.
> my action class successfully running and retrieving the data but unable to
> show it on my jsp page.so if any body have idea about it please help me
> my action class is
>
> [code]
>
> package com.action;
>
> import java.util.Iterator;
> import java.util.List;
>
> import javax.persistence.EntityManager;
> import javax.persistence.EntityManagerFactory;
> import javax.persistence.EntityTransaction;
> import javax.persistence.Persistence;
> import javax.persistence.Query;
>
> import org.apache.struts2.convention.annotation.*;
> import org.apache.struts2.rest.DefaultHttpHeaders;
>
> import com.opensymphony.xwork2.ActionSupport;
>
> @ParentPackage(value="default")
> @Namespace("/")
> @ResultPath(value="/")
>
>
> public class noOfUsers extends ActionSupport {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> private String firstname;
> List myList;
>
> private String user;
>
> @SuppressWarnings("unchecked")
> @Action(value="usersn",results={
> @Result(name="create",type="tiles",location="users")
> })
>
> public static DefaultHttpHeaders create(){
> EntityManagerFactory emf=Persistence.createEntityManagerFactory("tujpa");
> EntityManager em=emf.createEntityManager();
> EntityTransaction entr=em.getTransaction();
> entr.begin();
> Query query=em.createQuery("select u.firstname from User u ");
> List myList=query.getResultList();
> System.out.println(myList);
> entr.commit();
> em.close();
> return new DefaultHttpHeaders("create");
> }
>
> public List getMyList(){
> return myList;
> }
> }
>
> [/code ]
>
>
> thanks in advance
> --
> View this message in context: http://old.nabble.com/display-data-of-action-class-on-jsp-in-struts2-tp31075171p31075171.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Re: display data of action class on jsp in struts2
Posted by Aaron Brown <aa...@thebrownproject.com>.
You declare myList again inside create method, so the data is never stored
in the class-level myList. When the jsp asks for the list, it's empty.
On Mar 5, 2011 8:59 AM, "shekhar16" <sh...@gmail.com> wrote:
>
> i m new to struts2,rest plugin and i m tring to retrieve data from
database
> through jpa and display it on jsp.
> my action class successfully running and retrieving the data but unable to
> show it on my jsp page.so if any body have idea about it please help me
> my action class is
>
> [code]
>
> package com.action;
>
> import java.util.Iterator;
> import java.util.List;
>
> import javax.persistence.EntityManager;
> import javax.persistence.EntityManagerFactory;
> import javax.persistence.EntityTransaction;
> import javax.persistence.Persistence;
> import javax.persistence.Query;
>
> import org.apache.struts2.convention.annotation.*;
> import org.apache.struts2.rest.DefaultHttpHeaders;
>
> import com.opensymphony.xwork2.ActionSupport;
>
> @ParentPackage(value="default")
> @Namespace("/")
> @ResultPath(value="/")
>
>
> public class noOfUsers extends ActionSupport {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> private String firstname;
> List myList;
>
> private String user;
>
> @SuppressWarnings("unchecked")
> @Action(value="usersn",results={
> @Result(name="create",type="tiles",location="users")
> })
>
> public static DefaultHttpHeaders create(){
> EntityManagerFactory emf=Persistence.createEntityManagerFactory("tujpa");
> EntityManager em=emf.createEntityManager();
> EntityTransaction entr=em.getTransaction();
> entr.begin();
> Query query=em.createQuery("select u.firstname from User u ");
> List myList=query.getResultList();
> System.out.println(myList);
> entr.commit();
> em.close();
> return new DefaultHttpHeaders("create");
> }
>
> public List getMyList(){
> return myList;
> }
> }
>
> [/code ]
>
>
> thanks in advance
> --
> View this message in context:
http://old.nabble.com/display-data-of-action-class-on-jsp-in-struts2-tp31075171p31075171.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>