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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]