Hi, all.
I've got an RFE. Background: The current jsp:setProperty tag supports only
primitive types, wrappers for primitive types, and arrays. I.e., it supports
int and Integer, byte and Byte, etc. So the bean to set properties on can
look like:
public class MyBean {
public void setAnInt(int i) {}
public void setAnInteger(Integer i) {}
public void setAnArray(Float[] f) {}
// ... and so on
// But these don't work:
public void setADate(java.util.Date date) {}
public void setADate(java.sql.Date date) {}
public void setAFile(java.io.File file) {}
public void setABeanProperty(MyBeanProperty myBeanProperty) {}
//this last is the most interesting. details below
}
Currently the unsupported types can be handled by scriplets, but in addition
to looking ugly they rule out use of property="*".
I propose the spec be expanded to include:
* java.util.Date
* java.sql.Date
* java.io.File
* **ANY** JavaBean
The last one is the most interesting. The following tag would then work:
<jsp:setProperty name="myBean" property="myBeanProperty"
value="a.java.bean.class.Name"/>
The JSP implementation would then introspect on myBean, learn that myBean's
property named "myBeanProperty" is of the type
"com.mycompany.MyBeanProperty" and then it would *instantiate* an instance
of the Java class name passed in as a value. I.e., it would call
Beans.instantiate(classLoader, "a.java.bean.class.Name"); if the
instantiation succeeds and the object is of the correct type, it will be
set.
This is especially useful when you want to be able to extend a web
application with a published API. Web pages can contain form input such as:
<form method="POST" action="setMyBean.jsp">
<select name="myBeanProperty>
<option value="a.vendor.bean.class.FirstImpl">Option One
<option value="a.vendor.bean.class.SecondImpl">Option Two
<!-- now an option NOT included by the vendor, but written as an extension,
without requiring any access to the vendor's source code -->
<option value="a.user.extension.ACustomImpl">Option Three
</select>
</form>
I've found this kind of form input to be extremely elegant and useful.
As for implementation of the changes I've proposed, it should be quite
straightforward. There are no compatibility issues for adding on additional
setProperty types, except that exceptions will no longer be thrown. To avoid
even this minor incompatibility, the tag could look like:
<jsp:setProperty name="myBean" property="*" instantiate="true"/>
(Attempt to instantiate any argument class that isn't otherwise recognized.)
For anyone interested, I have a working custom tag and tld that implements
everything I've described here.
So what do you think? Would this be useful?
Cheers,
Jonathan
(I've submitted an RFE for this, and it was suggested I post to jsp-interest
for feedback. I'll put in a more detailed RFE after I hear from other
people.)
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets