I am developing an application with struts,hibernate and JSP.
I have an action class where I am using criteria to retrieve value from database.
I need to show that particular value in my JSP page.
Currently I am using the following : -
ProductForm prdForm=criteria.list(); (which returns only one record)
My JSP page
<bean:write name="ProductForm" property="Id" />
Is this a correct way to displaye values in JSP using struts tags?
Firstly, when you are writing criteria.list(), collect it in a list instead of form object.
a. List<ProductForm> productFormList = criteria.list();
Going ahead if you are sure of receiving only one record, you can do a get(0) on the list as
b. ProductForm productForm = productFormList.get(0);
Next, you do not have to save it in session. On your JSP, you can directly iterate over productFormList (if you retrieve multiple rows), and display the values using <bean:write>, else directly use the form from line b. (if you are getting only one row), to display the values.
gives me a ClassCastException as my criteria returns me list of objects of type Product(Which is my POJO)
how can I cast it to my form class object (ProductForm) ?
how can I retrieve object of type Part from the list (or single record) returned by Criteria?
your bean should have getter and setter method / the variable should be public.
Joined: Aug 07, 2009
Can anyone please suggest me (or explain me) a link having proper example of <bean-write>?
I searched for the net and got many different examples but none up to the mark.
<bean-write name="myForm" property="myProperty">
What should be myForm?
Name of my Form bean or object of my Form bean created in my Action Class
I am really not getting this.
It will be very helpful if someone helps me out of this.
Thanks in Advance
Joined: Jul 21, 2011
myForm would be the 'id' of the <jsp:useBean>. This is one of the ways, however in general 'name' specifies the attribute name of the bean whose property is accessed to retrieve the value specified by property (if specified). If property is not specified, the value of this bean itself will be rendered.