Problem with bean:write and bean:define
Hi, Maybe this is more related on how reflection works, But I'm trying to understand the behavior here... Here's my situation: I have a Bean under request scope with the following methods: public MyBean { private java.util.Calendar startDate; public void setStartDate(Calendar newValue) { this.startDate = newValue; } public void setStartDate(java.util.Date newValue) { if (this.startDate == null) { this.startDate = Calendar.getInstance(); } this.startDate.setTime(newValue); } public Calendar getStartDate() { return this.startDate; } } Well, forget all the typos, since I just created the above code as example... But when I have a scenario like the above (two setters with different signature - can be Calendars, int and Integer, long and Long, etc...) the above tags, bean:write and bean:define complains that can't find a getter method for property ???. I tried with jsp:useBean and jsp:getProperty and the error was: Property ??? in package.class is write only Am I missing something? I don't know much about reflection, but I know that it's possible to declare the method signature while trying to get reference to a method, and it seems that it's not the case here... Any explanation is appreciated... Right now, I just fixed the problem by removing one of the setter methods. Regards, Marcelo -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Problem with bean:write and bean:define
This seems to be an obvious limitation based on Java reflection. By overloading the setStartDate method you seem to be confusing the write/read permission mechanism available from JSP. By adding a second method you seem to lose read capability altogether. Here's a little workaround - make the parameter type in setStartDate a simple object and then have the method sort out what is has been called. You pretty much are shifting things into runtime this way and you won't have this signature problem. Of course you can't do this with a simple String (not an object in Java), so you might want to write yourself a little wrapper object. I know - this gets ugly - but unless someone else has figured out how to circumvent this flaw it's what I might try... Cheers! - Original Message - From: Marcelo Caldas [EMAIL PROTECTED] To: Struts Mailing List [EMAIL PROTECTED] Sent: Wednesday, January 16, 2002 10:55 AM Subject: Problem with bean:write and bean:define Hi, Maybe this is more related on how reflection works, But I'm trying to understand the behavior here... Here's my situation: I have a Bean under request scope with the following methods: public MyBean { private java.util.Calendar startDate; public void setStartDate(Calendar newValue) { this.startDate = newValue; } public void setStartDate(java.util.Date newValue) { if (this.startDate == null) { this.startDate = Calendar.getInstance(); } this.startDate.setTime(newValue); } public Calendar getStartDate() { return this.startDate; } } Well, forget all the typos, since I just created the above code as example... But when I have a scenario like the above (two setters with different signature - can be Calendars, int and Integer, long and Long, etc...) the above tags, bean:write and bean:define complains that can't find a getter method for property ???. I tried with jsp:useBean and jsp:getProperty and the error was: Property ??? in package.class is write only Am I missing something? I don't know much about reflection, but I know that it's possible to declare the method signature while trying to get reference to a method, and it seems that it's not the case here... Any explanation is appreciated... Right now, I just fixed the problem by removing one of the setter methods. Regards, Marcelo -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Problem with bean:write and bean:define
could be that bean:write needs a String to be returned by the getter ... and not a Calendar ? since it is a String that is inserted ... Struts Users Mailing List [EMAIL PROTECTED] wrote: Hi, Maybe this is more related on how reflection works, But I'm trying to understand the behavior here... Here's my situation: I have a Bean under request scope with the following methods: public MyBean { private java.util.Calendar startDate; public void setStartDate(Calendar newValue) { this.startDate = newValue; } public void setStartDate(java.util.Date newValue) { if (this.startDate == null) { this.startDate = Calendar.getInstance(); } this.startDate.setTime(newValue); } public Calendar getStartDate() { return this.startDate; } } Well, forget all the typos, since I just created the above code as example... But when I have a scenario like the above (two setters with different signature - can be Calendars, int and Integer, long and Long, etc...) the above tags, and complains that can't find a getter method for property ???. I tried with and and the error was: Property ??? in is write only Am I missing something? I don't know much about reflection, but I know that it's possible to declare the method signature while trying to get reference to a method, and it seems that it's not the case here... Any explanation is appreciated... Right now, I just fixed the problem by removing one of the setter methods. Regards, Marcelo -- To unsubscribe, e-mail: For additional commands, e-mail: -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]