|
From: <jue...@we...> - 2004-01-30 22:18:38
|
FYI, I've just made my suggestion work through the introduction of a new =
feature: String arrays can now be converted to other arrays, just like =
Lists can. So registering an editor for an individual InetAddress would =
work now, even if populated with a String array: Each String gets =
converted to an InetAddress, just like each List element would get =
converted when populated with a List.
=20
This code will be included in the upcoming 1.0 RC1.
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag von =
j=FCrgen h=F6ller [werk3AT]
Gesendet: Fr 30.01.2004 23:01
An: Les A. Hazlewood
Cc: spr...@li...
Betreff: [Springframework-user] Re [springframework-developer] =
PropertyEditor question
Les,
First of all, my last suggestion really doesn't work: You'd need to have =
a property value of type List to benefit from individual conversion of =
array elements - a String array doesn't work here. Obviously, you cannot =
influence this if binding request parameters, so that's ruled out.
I've just checked that your initial approach of trying to bind to a =
java.util.Set doesn't work either: Your PropertyEditor will just get =
invoked for *String* values, not for *String array* values. To verify =
that, you could try if it works for a *single* InetAddress request =
parameter.
So I'm afraid you have to resort to manual binding code, for example in =
a custom onBindAndValidate implementation: Use a different request =
parameter name, fetch that parameter array from the request there, =
convert it to InetAddress objects, and invoke the corrresponding setter =
on your form object.
Juergen
________________________________
Von: Les A. Hazlewood [mailto:le...@ha...]
Gesendet: Fr 30.01.2004 16:54
An: j=FCrgen h=F6ller [werk3AT]
Cc: col...@ex...
Betreff: Re: [springframework-developer] PropertyEditor question
> Changing the Set to a InetAddress[] and
> registering the custom editor for a single InetAddress.class should
> definitely work.
Juergen, thanks very much for your reply. However, that didn't work. I =
have no
idea why, as everything tells me it should work.
I think the problem remains that the binder is never associating my
InetAddressEditor with the InetAddress.class. Otherwise I wouldn't =
receive the
'Using property editor [null]' message from the BeanWrapperImpl.
Just to be clear, here's my controller method:
protected void initBinder( HttpServletRequest request,
ServletRequestDataBinder binder ) {
//calls superclass which sets other application specific Editors =
common to
//all forms (i.e. the superclass is a subclass of =
SimpleFormController
//and it registers a UUID editor since uuid's are common to almost =
all our
//forms)
//Note to Jeurgen: The UUID editor is always bound and functions =
properly.
super.initBinder(request, binder);
//register editors for this form in particular:
binder.registerCustomEditor( InetAddress.class, new =
InetAddressEditor());
}
The InetAddressEditor (subclassing from PropertyEditorSupport) only has =
two
methods defined: setAsText(String text) and String getAsText();
The jsp code (shows all ip addresses just fine, each in their own input =
box, the
controller just breaks when I submit the form):
<td>
<spr:bind path=3D"workstation.inetAddressArray">
<c:forEach var=3D"inetAddress" =
items=3D"${workstation.inetAddressArray}">
<input name=3D"inetAddressArray" type=3D"text" size=3D"39" =
maxlength=3D"39"
value=3D"<c:out value=3D"${inetAddress.hostAddress}"/>"/><br/>
</c:forEach>
<a href=3D"javascript:addIp();">Add IP</a>
<c:if test=3D"${addIp =3D=3D true}">
<input name=3D"inetAddressArray" type=3D"text" size=3D"39" =
maxlength=3D"39"/>
</c:if>
</spr:bind>
</td>
The debug output when I try to submit my form:
DEBUG [BeanWrapperImpl] Convert: String to [class =
[Ljava.net.InetAddress;]
DEBUG [BeanWrapperImpl] Using property editor [null]
DEBUG [BeanWrapperImpl] About to invoke write method [public void
com.test.computer.SimpleComputerInfo.setInetAddressArray(java.net.InetAdd=
ress[])]
on object of class [com.test.workstation.SimpleWorkstationInfo]
DEBUG [BeanWrapperImpl] About to invoke write method [public void
com.test.computer.SimpleComputerInfo.setName(java.lang.String)] on =
object of
class [com.test.workstation.SimpleWorkstationInfo]
DEBUG [BeanWrapperImpl] Invoked write method [public void
com.test.computer.SimpleComputerInfo.setName(java.lang.String)] with =
value
[Development Workstation]
DEBUG [WorkstationFormController] Data binding errors: 1
DEBUG [SessionFactoryUtils] Opening Hibernate session
DEBUG [HibernateTemplate] Eagerly flushing Hibernate session
DEBUG [SessionFactoryUtils] Closing Hibernate session
DEBUG [SessionFactoryUtils] Opening Hibernate session
DEBUG [HibernateTemplate] Eagerly flushing Hibernate session
DEBUG [SessionFactoryUtils] Closing Hibernate session
DEBUG [SessionFactoryUtils] Opening Hibernate session
DEBUG [HibernateTemplate] Eagerly flushing Hibernate session
DEBUG [SessionFactoryUtils] Closing Hibernate session
DEBUG [DispatcherServlet] Will render view in DispatcherServlet with =
name
'SpringFrontController'
DEBUG [JstlView] Rendering view with name 'workstationFormView' with
model=3D[{facility=3Dcom.test.model.Reference@834e7,
org.springframework.validation.BindException.workstation=3Dorg.springfram=
ework.validation.BindException:
BindException: 1 errors; FieldError occurred in object [workstation] on
[inetAddressArray]: rejectedValue [10.0.0.1];
codes=3D[typeMismatch.workstation.inetAddressArray,typeMismatch.inetAddre=
ssArray,typeMismatch];
args=3D[null]; defaultMessage=3D[Failed to convert property value of =
type
[java.lang.String] to required type [[Ljava.net.InetAddress;] for =
property
named 'inetAddressArray'; nested exception is:
java.lang.IllegalArgumentException: argument type mismatch],
workstation=3Dcom.test.workstation.SimpleWorkstationInfo@cc0f9f,
controlRooms=3D[com.test.model.Reference@c92ed6],
workstations=3D[com.test.model.Reference@21f46a,
com.test.model.Reference@13598c3]}] and static attributes=3D[{}]
Is this truly a bug, and should I submit it to JIRA? Does calling
super.initBinder on my superclass break something (even though the =
superclass
is an application specific controller that extends =
SimpleFormController)? I
couldn't imagine that it would, since all the superclass does is =
register a
UUID Editor and nothing more. Or am I completely off the map, and the =
error
entirely my own?
Gratefully,
Les
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Springframework-user mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-user
|