SpringRoo 2.0.RC1 - How can i use date Calenderfields in entityFormatExpression and got correct format

删除回忆录丶 提交于 2020-01-17 07:04:11

问题


date Calendar

When i use date Calender field in entityFormatExpression i got a

entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"
field date --fieldName birthDay --type java.util.Calendar --notNull --dateTimeFormatPattern "dd.MM.yyyy"

Log Warning

2017-03-22 10:43:55.738  WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableExcep
tion: Could not write content: Failed to convert from type [org.springframework.roo.petclinic.domain
.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='M
imi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAl
lFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSa
vings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,of
fset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,st
artDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTi
me=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF
_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0
,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_T
O_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_C
ANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petc
linic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationExceptio
n: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNu
ll @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.Grego
rianCalendar to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2Dat
aWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException
: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to type [java.lang.Stri
ng] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weight='4.5', birthDay=
'java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=tru
e,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600
000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],fi
rstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_
OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=
0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='T
he given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The give
n Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domain.Pet@1f'; nested
exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:(pos 0): Type conv
ersion problem, cannot convert from @javax.validation.constraints.NotNull @javax.persistence.Tempora
l @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalendar to java.lang.Str
ing (through reference chain: io.springlets.data.web.select2.Select2DataWithConversion["results"])
2017-03-22 10:43:55.754  WARN - QP: - 6424 --- [io-8082-exec-10] .w.s.m.s.DefaultHandlerExceptionRes
olver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessa
geNotWritableException: Could not write content: Failed to convert from type [org.springframework.ro
o.petclinic.domain.Pet] to type [java.lang.String] for value 'Pet {id='1', version='0', sendReminder
s='false', name='Mimi', weight='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFi
eldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",of
fset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[i
d=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMont
h=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,en
dDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=20
17,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_
IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFS
ET=0]', ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', IT
ERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='The given Iterable of items to add can't be null!'}org.spring
framework.roo.petclinic.domain.Pet@1f'; nested exception is org.springframework.expression.spel.Spel
EvaluationException: EL1001E:(pos 0): Type conversion problem, cannot convert from @javax.validation
.constraints.NotNull @javax.persistence.Temporal @org.springframework.format.annotation.DateTimeForm
at java.util.GregorianCalendar to java.lang.String (through reference chain: io.springlets.data.web.
select2.Select2DataWithConversion["results"]); nested exception is com.fasterxml.jackson.databind.Js
onMappingException: Failed to convert from type [org.springframework.roo.petclinic.domain.Pet] to ty
pe [java.lang.String] for value 'Pet {id='1', version='0', sendReminders='false', name='Mimi', weigh
t='4.5', birthDay='java.util.GregorianCalendar[time=1490137200000,areFieldsSet=true,areAllFieldsSet=
true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=36000
00,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=360000
0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWee
k=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,
endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2017,MONTH=2,WEEK_OF_YEAR=12,WE
EK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOU
R_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]', ITERABLE_TO_ADD_CANT_
BE_NULL_MESSAGE='The given Iterable of items to add can't be null!', ITERABLE_TO_REMOVE_CANT_BE_NULL
_MESSAGE='The given Iterable of items to add can't be null!'}org.springframework.roo.petclinic.domai
n.Pet@1f'; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1001E:
(pos 0): Type conversion problem, cannot convert from @javax.validation.constraints.NotNull @javax.p
ersistence.Temporal @org.springframework.format.annotation.DateTimeFormat java.util.GregorianCalenda
r to java.lang.String (through reference chain: io.springlets.data.web.select2.Select2DataWithConver
sion["results"])

When i create a Visit the Pet don't show in List.

date Date

When i use an date Date field and create a Visit the Pet shown in List but the format is not correct.

In Clinic Eaxmpel i have set a birthDay field to Pet and use it in entityFormatExpression

entity jpa --class ~.domain.Pet --sequenceName PET_SEQ --entityFormatExpression "#{name} (#{type}) birthDay: #{birthDay}"

focus --class ~.domain.Pet
field date --fieldName birthDay --type java.util.Date --notNull --dateTimeFormatPattern "dd.MM.yyyy"

I have set dateTimeFormatPattern "dd.MM.yyyy"

In create edit/ view i see

enter image description here

When i create a visit Object i see

enter image description here

This is not the format i used for this field.


回答1:


The conversion to String when the JSON data is sent to the select2 component is performed by the EntityExpression utilities which are registered in the ConversionService.

Those utilities use the SpEl support to parse the expression and convert the entity to a String. It seems the SpEl expression isn't using or doesn't have access to the ConversionService itself to convert to String the object properties included in the expression.

I've created an issue in the Springlets project to take a look at the problem.



来源:https://stackoverflow.com/questions/42947604/springroo-2-0-rc1-how-can-i-use-date-calenderfields-in-entityformatexpression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!