Bean props from params [Was: Re: beans, beans, they're good for your heart (tms)]
Frank, I think that what you're running into are the limitations of assigning properties from a string value. From what I understand, JSP is effectively doing a setProperty() on the request parameters that match properties in your bean, but remember that these parameters are passed as Strings. I believe that the relevant part of the JSP spec (I'm quoting from the 1.1 version), Section 2.13.2, paragraph 3, page 65: Properties in a Bean can be set from one or more parameters in the request object, from a String constant, or from a compted request-time expression. Simple and indexed properties can be set using setProperties. The only types of properties that can be assigned to/from String constants and request parameter values are those listed in table 2-4; the conversion applied is shown in that table. The table lists only the primitive types -- boolean, byte, char, double, int, float and long. I think that what you would want to do in this case is to have add an extra date property to your bean that gets/sets the date as either a long (internal format) or as a string that you can parse. For example: public long getUserDateInternal() { returns getUserDate().getTime(); } public void setUserDateInternal(long value) { setUserDate(new Date(value)); } Hope this helps. Yours, JonTom John Thomas Kittredge ITA Software, Inc Cambridge, Massachusetts Frank Starsinic wrote: i noticed that when using beans, they automatically get populated from a webpage Form when the form field names are the same as the bean properties, and hence, good for your heart. this works for both Integer and String types in my test example. for some reason, a Date type is not working. does anyone know why this would not happen. my bean name is "foo" and my bean has a test() method that dumps out the bean properties so i can check it in my JSP page like this %=foo.test()%> when i do that i get this Host: localhost Port: 3453 Date: null the setDate() method seems to be occuring but not populating the date property in the bean as i expect it might. Also, in the web form, for the date i'm just putting in 4/5/1999 or something like that. thanks,frank === To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". FAQs on JSP can be found at: http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html
Re: Bean props from params [Was: Re: beans, beans,they're good for your heart (tms)]
Sorry, In my last reply, I wasn't "focused" on the important fact that this date value is coming from a webform. What you would really want in this case is a way to specify a nested setProperty. So let's say you create a bean class that can represent a date and has separate numeric properties for month, day-of-month, year, as they are represented in your form. (This sounds just like the java.util.Date class, doesn't it? But then all those methods have been deprecated. Shh! Don't tell anyone!) Then your input element could be something like this input type=input name="userDate.year"> and JSP would automatically call beanFoo.setYear(value). Unfortunately, I don't believe that that is currently in the JSP spec. I think it was in an earlier draft, but got taken out. Maybe it will show up later. Sure would be useful. Yours, JonTom John Thomas Kittredge ITA Software, Inc Cambridge, Massachusetts JonTom Kittredge wrote: Frank, I think that what you're running into are the limitations of assigning properties from a string value. From what I understand, JSP is effectively doing a setProperty() on the request parameters that match properties in your bean, but remember that these parameters are passed as Strings. I believe that the relevant part of the JSP spec (I'm quoting from the 1.1 version), Section 2.13.2, paragraph 3, page 65: Properties in a Bean can be set from one or more parameters in the request object, from a String constant, or from a compted request-time expression. Simple and indexed properties can be set using setProperties. The only types of properties that can be assigned to/from String constants and request parameter values are those listed in table 2-4; the conversion applied is shown in that table. The table lists only the primitive types -- boolean, byte, char, double, int, float and long. I think that what you would want to do in this case is to have add an extra date property to your bean that gets/sets the date as either a long (internal format) or as a string that you can parse. For example: public long getUserDateInternal() { returns getUserDate().getTime(); } public void setUserDateInternal(long value) { setUserDate(new Date(value)); } Hope this helps. Yours, JonTom John Thomas Kittredge ITA Software, Inc Cambridge, Massachusetts
Re: Beans, beans, ....
At 12:59 AM 6/17/99 -0400, Bill O'Keefe wrote: At 12:36 AM 6/17/99 -0400, Brad Neuberg wrote: On Thu, 17 Jun 1999, Bill O'Keefe wrote: Chris, I have a question on using beans from JSP. According to my understanding, the usebean: tag can be used to access a normal bean, but one has to use the JNDI API to lookup a proxy to access an Enterprise JavaBean (ejb). Thus, one has to write a block of Java code in the JSP to get access to an ejb. Is this true, or does the usebean: tag also support ejbs, and if so, how? Thanks. -- Bill JSP 1.1 is supposed to have more EJB support. However, the details are sketchy. To make sure we're starting with a clear understanding: EJB's have nothing to do with regular JavaBeans (except that both happen to have the word 'bean' in their names, which was probably a bad marketing choice). If you want your JSP page to be an EJB client, then yes, you will have to follow the EJB client API from within your jsp page. Which means that you will have to use JNDI to locate your EJB. This has absolutely nothing to do with the way JavaBeans and JSP works. Thanks for the response. This was pretty much the same conclusion I came to, but I just wanted to make sure I wasn't missing something. It took me a few days of spec reading to determine that the only real similiarity between JavaBeans and Enterprise JavaBeans is that they are both components, with completely different characteristics (one for client side app development and the other for server-side development). Since JSP and EJB's are both part of the J2EE (Java 2 Enterprise Edition), they may provide more integration in JSP 1.1. But even if they make some things invisible, I would guess that under the covers, JNDI and the rest of the EJC client API would have to be followed. This is basically what I was asking, i.e., are there any EJB-specific options available with the usebean: tag to make things simpler for JSP developers who want to access EJBs. I realize it's not rocket science to locate an EJB via JNDI, but it seems to me that this causes the JSP to get 'cluttered' with some repeated boiler-plate code that could be hidden via a usebean (or maybe useEJB???) tag. Sounds like this is still TBD from what you're saying. Actually, couldn't you just have a servlet that looked up the EJB through the JNDI and then called the JSP file, passing the found EJB to the JSP file through an attribute in the Request object? I guess that would work, though I'd have to come up with an EJB attribute naming scheme that would not collide with existing attribute names in the request object. I guess it shouldn't be too hard to pick some obsure names for the EJB attributes to make the collision unlikely (I could even check first if I was real paranoid :-) Thanks for the suggestion. I still would like to see some support added to JSP to have a standard way to locate an EJB from a JSP (i.e., using some standard JSP tag). Brad, Well, I just re-read your response (and my somewhat lukewarm thanks :-), and what you suggested makes sense to me now! As a newbie to the servlet/bean/JSP world, I was confused by request 'attributes' and request 'parameters'. Now that I'm an 'expert' :-), your solution makes sense to me, and seems quite workable. Thanks for the tip. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Beans, beans, ....
I have a question on using beans from JSP. According to my understanding, the usebean: tag can be used to access a normal bean, but one has to use the JNDI API to lookup a proxy to access an Enterprise JavaBean (ejb). Thus, one has to write a block of Java code in the JSP to get access to an ejb. Is this true, or does the usebean: tag also support ejbs, and if so, how? Thanks. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: Beans, beans, ....
Bill O'Keefe wrote: I have a question on using beans from JSP. According to my understanding, the usebean: tag can be used to access a normal bean, but one has to use the JNDI API to lookup a proxy to access an Enterprise JavaBean (ejb). Thus, one has to write a block of Java code in the JSP to get access to an ejb. Is this true, or does the usebean: tag also support ejbs, and if so, how? Thanks. -- Bill JSP 1.1 is supposed to have more EJB support. However, the details are sketchy. To make sure we're starting with a clear understanding: EJB's have nothing to do with regular JavaBeans (except that both happen to have the word 'bean' in their names, which was probably a bad marketing choice). If you want your JSP page to be an EJB client, then yes, you will have to follow the EJB client API from within your jsp page. Which means that you will have to use JNDI to locate your EJB. This has absolutely nothing to do with the way JavaBeans and JSP works. Since JSP and EJB's are both part of the J2EE (Java 2 Enterprise Edition), they may provide more integration in JSP 1.1. But even if they make some things invisible, I would guess that under the covers, JNDI and the rest of the EJC client API would have to be followed. cc === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: Beans, beans, ....
On Thu, 17 Jun 1999, Bill O'Keefe wrote: Chris, I have a question on using beans from JSP. According to my understanding, the usebean: tag can be used to access a normal bean, but one has to use the JNDI API to lookup a proxy to access an Enterprise JavaBean (ejb). Thus, one has to write a block of Java code in the JSP to get access to an ejb. Is this true, or does the usebean: tag also support ejbs, and if so, how? Thanks. -- Bill JSP 1.1 is supposed to have more EJB support. However, the details are sketchy. To make sure we're starting with a clear understanding: EJB's have nothing to do with regular JavaBeans (except that both happen to have the word 'bean' in their names, which was probably a bad marketing choice). If you want your JSP page to be an EJB client, then yes, you will have to follow the EJB client API from within your jsp page. Which means that you will have to use JNDI to locate your EJB. This has absolutely nothing to do with the way JavaBeans and JSP works. Thanks for the response. This was pretty much the same conclusion I came to, but I just wanted to make sure I wasn't missing something. It took me a few days of spec reading to determine that the only real similiarity between JavaBeans and Enterprise JavaBeans is that they are both components, with completely different characteristics (one for client side app development and the other for server-side development). Since JSP and EJB's are both part of the J2EE (Java 2 Enterprise Edition), they may provide more integration in JSP 1.1. But even if they make some things invisible, I would guess that under the covers, JNDI and the rest of the EJC client API would have to be followed. This is basically what I was asking, i.e., are there any EJB-specific options available with the usebean: tag to make things simpler for JSP developers who want to access EJBs. I realize it's not rocket science to locate an EJB via JNDI, but it seems to me that this causes the JSP to get 'cluttered' with some repeated boiler-plate code that could be hidden via a usebean (or maybe useEJB???) tag. Sounds like this is still TBD from what you're saying. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". Actually, couldn't you just have a servlet that looked up the EJB through the JNDI and then called the JSP file, passing the found EJB to the JSP file through an attribute in the Request object? === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: Beans, beans, ....
At 12:36 AM 6/17/99 -0400, Brad Neuberg wrote: On Thu, 17 Jun 1999, Bill O'Keefe wrote: Chris, I have a question on using beans from JSP. According to my understanding, the usebean: tag can be used to access a normal bean, but one has to use the JNDI API to lookup a proxy to access an Enterprise JavaBean (ejb). Thus, one has to write a block of Java code in the JSP to get access to an ejb. Is this true, or does the usebean: tag also support ejbs, and if so, how? Thanks. -- Bill JSP 1.1 is supposed to have more EJB support. However, the details are sketchy. To make sure we're starting with a clear understanding: EJB's have nothing to do with regular JavaBeans (except that both happen to have the word 'bean' in their names, which was probably a bad marketing choice). If you want your JSP page to be an EJB client, then yes, you will have to follow the EJB client API from within your jsp page. Which means that you will have to use JNDI to locate your EJB. This has absolutely nothing to do with the way JavaBeans and JSP works. Thanks for the response. This was pretty much the same conclusion I came to, but I just wanted to make sure I wasn't missing something. It took me a few days of spec reading to determine that the only real similiarity between JavaBeans and Enterprise JavaBeans is that they are both components, with completely different characteristics (one for client side app development and the other for server-side development). Since JSP and EJB's are both part of the J2EE (Java 2 Enterprise Edition), they may provide more integration in JSP 1.1. But even if they make some things invisible, I would guess that under the covers, JNDI and the rest of the EJC client API would have to be followed. This is basically what I was asking, i.e., are there any EJB-specific options available with the usebean: tag to make things simpler for JSP developers who want to access EJBs. I realize it's not rocket science to locate an EJB via JNDI, but it seems to me that this causes the JSP to get 'cluttered' with some repeated boiler-plate code that could be hidden via a usebean (or maybe useEJB???) tag. Sounds like this is still TBD from what you're saying. Actually, couldn't you just have a servlet that looked up the EJB through the JNDI and then called the JSP file, passing the found EJB to the JSP file through an attribute in the Request object? I guess that would work, though I'd have to come up with an EJB attribute naming scheme that would not collide with existing attribute names in the request object. I guess it shouldn't be too hard to pick some obsure names for the EJB attributes to make the collision unlikely (I could even check first if I was real paranoid :-) Thanks for the suggestion. I still would like to see some support added to JSP to have a standard way to locate an EJB from a JSP (i.e., using some standard JSP tag). -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: Beans, beans, ....
I guess that would work, though I'd have to come up with an EJB attribute naming scheme that would not collide with existing attribute names in the request object. I guess it shouldn't be too hard to pick some obsure names for the EJB attributes to make the collision unlikely (I could even check first if I was real paranoid :-) Thanks for the suggestion. I still would like to see some support added to JSP to have a standard way to locate an EJB from a JSP (i.e., using some standard JSP tag). -- Bill And it would mean you'd have to write servlets (yuk!). Perhaps the taglib mechanism would help? I haven't looked at it throughly but it is supposed to be a mechanism for extending the syntax... Or maybe Sun could give us some idea of what they are thinking about after JavaOne and we could discuss it further? (Don't think THATS going to happen!) -- Richard Vowles, Senior Systems Engineer, Inprise New Zealand MAIL: [EMAIL PROTECTED], [EMAIL PROTECTED] HTTP: http://www.esperanto.org.nz [my messages contain my own opinions, not those of my employer] === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".