Re: Setting the properties of a javabean in JSP
- From: vk02720@xxxxxxxxx
- Date: Thu, 11 Dec 2008 14:25:23 -0800 (PST)
On Dec 11, 2:02 pm, Lew <l...@xxxxxxxxxxxxx> wrote:
harryos wrote:
... javabean properties using user input values ...
userinput.jsp
------------------
...
<body>
<h2>Entry Form</h2> ...
<jsp:useBean id="userB" class="org.mypackage.user.UserBean" >
<jsp:setProperty name="userB" property="*"/>
</jsp:useBean>
...
where the UserBean.java is
public class UserBean implements java.io.Serializable{...
Why do UserBean need to implement Serializable interface? I tried it
without implementing Serializable and the fields are set correctly
according to the user input .
You will not see any difference in setting fields with or without
implementing Serializable because it is a marker interface and does
not require you to implement any methods.
Isn't this implements clause unnecessary?
It depends on the scope where the bean lives. If it ever needs to
live at session scope, it will need to be Serializable for most
containers that do any kind of load balancing or session migration.
Conceptually since the bean represents information that is passed
around, even if only at request scope, it makes sense to think of it
as Serializable even if it isn't, so there's a pressure to implement
it that way. If the bean doubles as an entity for persistence
purposes, it pretty much has to be Serializable to fulfill that
function effectively.
Correct. Found this link useful for more on HttpSession.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/cprs_best_practice.html
Suggests Implement the java.io.Serializable interface when developing
new objects to be stored in the HTTP session. as a best practice.
In the Bloch reference that John B. Matthews cites,
<http://java.sun.com/docs/books/effective/>,
the author discusses the commitment embodied in making a class
Serializable. For entity-like objects such as the one under
discussion here, this doesn't pose too much additional burden since
the 'Serializable'ness is over the publicly accessible (via methods)
attributes anyway.
--
Lew- Hide quoted text -
- Show quoted text -
.
- References:
- Setting the properties of a javabean in JSP
- From: harryos
- Re: Setting the properties of a javabean in JSP
- From: Lew
- Setting the properties of a javabean in JSP
- Prev by Date: Multiple Views to a Model
- Next by Date: Re: Multiple Views to a Model
- Previous by thread: Re: Setting the properties of a javabean in JSP
- Next by thread: problem with sourcepath option
- Index(es):
Relevant Pages
|