Comments (4)
Hi
Interesting problem. Does this field has an JsonDeserializer?
If yes you could handle this case in the deserializer.
How does the json look that the client is sending to the server?
Ralph
On Wed, Aug 8, 2012 at 5:01 PM, salamoun [email protected] wrote:
Hello,
I have ExtJS formpanel that has Date field. But this field is optional, so
user can leave it empty.
But when form is saved over FORM_SUBMIT method I get the error:
Failed to convert property value of type 'java.lang.String' to required
type 'java.util.Date' for property 'startOfService'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String to type
@org.codehaus.jackson.map.annotate.JsonSerialize java.util.Date for value
''; nested exception is java.lang.IllegalArgumentExceptionI cannot figure how to set this field as optional. So when contains empty
string I need field be ignored.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/39.
from extdirectspring.
Created a small test application and this is indeed a problem.
The client sends something like this when the datefield is empty
extTID=5&extAction=formSubmitController&extMethod=handleFormSubmit&extType=rpc&extUpload=false&date=&remarks=
and then Spring somehow gets an empty String and tries to convert that to a
Date. There is nothing we can do in ExtDirectSpring because FORM_POST
methods are handled by Spring and also the conversion of the request
parameters into a bean.
I'm trying to find a solution in the Spring Forum.
Ralph
On Wed, Aug 8, 2012 at 6:00 PM, Ralph Schaer [email protected] wrote:
Hi
Interesting problem. Does this field has an JsonDeserializer?
If yes you could handle this case in the deserializer.How does the json look that the client is sending to the server?
Ralph
On Wed, Aug 8, 2012 at 5:01 PM, salamoun [email protected] wrote:
Hello,
I have ExtJS formpanel that has Date field. But this field is optional,
so user can leave it empty.
But when form is saved over FORM_SUBMIT method I get the error:
Failed to convert property value of type 'java.lang.String' to required
type 'java.util.Date' for property 'startOfService'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String to type
@org.codehaus.jackson.map.annotate.JsonSerialize java.util.Date for value
''; nested exception is java.lang.IllegalArgumentExceptionI cannot figure how to set this field as optional. So when contains empty
string I need field be ignored.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/39.
from extdirectspring.
Found a solution in the Spring forum. It looks like you have to add a
@InitBinder method.
I added this code in the same @controller class where the FORM_POST is
located and it worked.
@InitBinder
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
CustomDateEditor editor = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class, editor);
}
Here the link to the post from the Spring forum:
http://forum.springsource.org/showthread.php?95577-How-do-I-make-Spring-accept-an-empty-value-for-a&highlight=form+submit+empty+date+field
Hope this works in your project as well.
Ralph
from extdirectspring.
It works. Perfect solution. Thank you.
from extdirectspring.
Related Issues (20)
- Move getComparison() method to the base Filter class
- Support null values in BooleanFilter
- Struggling to work out what dependencies extdirectspring has HOT 2
- AuthenticationPrincipal moves into another package with Spring Security 4
- Inecting CDI Beans HOT 4
- Changing Jackson object mapper naming strategy impacts API json HOT 2
- Store filter syntax HOT 8
- @ExtDirectMethod(value = STORE_READ, jsonView=) is ignored HOT 4
- Default value for Ext Direct Remoting API variable name changes in Ext JS 6.0.1
- Static methods for ExtDirectStoreResult, ExtDirectFormLoadResult, ExtDirectFormPostResult, ExtDirectRawJsonStoreResult HOT 2
- Model Generator APT source? HOT 1
- Problem with grid grouping HOT 2
- org.springframework.web.bind.annotation.RequestParam.name HOT 1
- Test fail HOT 4
- Model CURD method metadata support HOT 2
- It's really nice to have methods as ExtDirectFormPostResult.create HOT 1
- Need to have special customization for variable "requestUrlString" in ApiController.buildAndCacheApiString
- Spring 5? HOT 2
- Router accepts text/plain requests which makes it CSRF vulnerable HOT 6
- Dependency org.springframework:spring-web, leading to CVE problem HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extdirectspring.