struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Linck, Ken" <Ken.Li...@crowncastle.com>
Subject RE: Is it bad when beans don't serialize?
Date Thu, 10 Jun 2004 20:24:18 GMT
Don't know if this is a "good" or "bad" answer.

Serialization is extremely important to us because of the clustering
solution we use.  We have to ensure objects stored in session implement the
serializable interface so each machine in the cluster can stay in synch with
each other and they do that via serializable interface.  So our solution to
determine size was based off that premise.

You should be able to tell what attribute it was trying to serialize when it
failed and zero in on the object that did not implement serializable.

Hopefully someone else can chime in on alternatives to computing size
without going the serializable route if that's what you might be looking
for.  This was the only example I found in our environment.

Ken

-----Original Message-----
From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Thursday, June 10, 2004 3:51 PM
To: struts
Subject: Is it bad when beans don't serialize?

A few days ago someone posted code to calculate the size of a user's session
(very helpful! thank you).
According to that code's serializiableTest method, the first version of the
SearchForm bean below serializes fine while the second doese not.

I thought as long as a no argument constructor was present everything was
ok?

/*
 * OK according to serializiableTest()
 */
public class SearchForm implemented Serializable {

 private String timePeriod;

 private LabelValueBean[] timePeriods;

 public SearchForm() {}

public LabelValueBean[] getTimePeriods() {  return new LabelValueBean[] {
  new LabelValueBean("Last 8 hours", "8"),
  new LabelValueBean("Last 12 hours", "12"),
  new LabelValueBean("Last 24 hours", "24")}; }

public String getTimePeriod() {
 return this.timePeriod;
}
public void setTimePeriod(String timePeriod) {  this.timePeriod =
timePeriod; }
 
}

-----

/*
 * NOT SERALIZED according to serializiableTest()  */ public class
SearchForm implemented Serializable {

 private String timePeriod;

 private LabelValueBean[] timePeriods;

 public SearchForm() {

  LabelValueBean[] timePeriods = new LabelValueBean[] {
   new LabelValueBean("Last 8 hours", "8"),
   new LabelValueBean("Last 12 hours", "12"),
   new LabelValueBean("Last 24 hours", "24")
  };

  this.timePeriods = timePeriods;

 }

public LabelValueBean[] getTimePeriods() {  return this.timePeriods; }

public String getTimePeriod() {
 return this.timePeriod;
}
public void setTimePeriod(String timePeriod) {  this.timePeriod =
timePeriod; }
 
}

On a different note, is it wise to include values for html select lists in
the ActionForm if they are fairly constant? I've found that it makes it
easier to display the information:

<html:select property="timePeriod">
 <html:optionsCollection property="timePeriods" /> </html:select>

As well as do error checking when the values are passed in via the
querystring to prevent user tampering. I can do this check in the
ActionForm's
validate() or in the Action's execute(). The example below is from execute:

Boolean hasValidTimePeriod = Boolean.FALSE; 

LabelValueBean[] timePeriods =
searchForm.getTimePeriods();

for (int i=0;i<timePeriods.length;i++) { if (timePeriods[i].getValue() ==
timePeriod) { hasValidTimePeriod = Boolean.TRUE; break; } }
		
if (hasValidTimePeriod.equals(Boolean.FALSE)) { // add error message to
ActionMessages }

Thanks,
Ron


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

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

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


Mime
View raw message