You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marsman <ma...@gmx.de> on 2011/01/08 18:25:37 UTC
How to persist null values with JSF2?
Hi!
Since migrated my application to JSF 2 I'm no able to persist an empty to
null converted value in the database. The values passed in
managedBean.setModel(model) are empty strings for example again. I'm looking
for a reason of this behaviour for a few days now and would be happy, if
anybody can help me. Here are some snippets of my code:
<h:form id="editAlbum">
...
<h:inputText id="year"
value="#{albumDetailBean.album.year}"></h:inputText>
<h:commandButton action="#{albumDetailBean.save}"
value="#{msg.buttonSave}"></h:commandButton>
</h:form>
@Entity
public class Album {
...
@Column
Integer year;
...
}
@ManagedBean
@SessionScoped
public class AlbumDetailBean {
@ManagedProperty(value="#{albumService}")
private AlbumService albumService;
private Album album;
public static AlbumDetailBean getInstance() {
FacesContext fc = FacesContext.getCurrentInstance();
return (AlbumDetailBean) fc.getApplication().evaluateExpressionGet(fc,
"#{albumDetailBean}", AlbumDetailBean.class);
}
public String save() {
// At this point, album.year is Integer(0) instead of null...!
if (album.getId() == null)
albumService.insert(album);
else
albumService.update(album);
return "success";
}
public Album getAlbum() {
return album;
}
public void setAlbum(Album album) {
this.album = album;
}
}
I've tried to implement an empty string to null converter and git the same
behaviour. I've even tried the new
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL property.
Without success. :-(
Titus
--
View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How to persist null values with JSF2?
Posted by Werner Punz <we...@gmail.com>.
It still is buggy, a friend of mine ran into issues with the latest
tomcat 7 afair, and as soon as he replaced it with juel after my advice
the issues were gone.
Werner
Am 10.01.11 17:22, schrieb Mark Struberg:
> nope, I found the tomcat 7 EL to be buggy back when I did need it (should re-evaluate it soon) and use juel now [1]
>
> LieGrue,
> strub
>
> [1] https://github.com/struberg/juel
>
> --- On Mon, 1/10/11, Marsman<ma...@gmx.de> wrote:
>
>> From: Marsman<ma...@gmx.de>
>> Subject: Re: How to persist null values with JSF2?
>> To: users@myfaces.apache.org
>> Date: Monday, January 10, 2011, 2:59 PM
>>
>> After googling another 2 hours I found the solution: Since
>> tomcat 6.0.16 we
>> have to add the org.apache.el.parser.COERCE_TO_ZERO=false
>> VM argument.
>> @Strub: Did you have set this VM argument too?
>>
>> For more infos:
>> http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jsf.html#EmptyToNullConverter
>> EmptyToNullConverter
>>
>>
>>
>> struberg wrote:
>>>
>>> Hmm, works perfectly over here when adding the
>> following to web.xml:
>>> <context-param>
>>>
>>>
>> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
>>>
>> <param-value>true</param-value>
>>> </context-param>
>>>
>>> as Jakob already suggested.
>>>
>>> LieGrue,
>>> strub
>>>
>>> --- On Mon, 1/10/11, Marsman<ma...@gmx.de>
>> wrote:
>>>
>>>> From: Marsman<ma...@gmx.de>
>>>> Subject: Re: How to persist null values with
>> JSF2?
>>>> To: users@myfaces.apache.org
>>>> Date: Monday, January 10, 2011, 1:52 PM
>>>>
>>>>
>>>> The action on the commandButton calls a
>> save()-Method in my
>>>> backing bean. At
>>>> this point, I got the empty fields instead of
>> null. You can
>>>> see this in my
>>>> initial post. I'm using JPA with Hibernate.
>>>>
>>>> Titus
>>>>
>>>>
>>>>
>>>> struberg wrote:
>>>>>
>>>>> Did you do your debugging in your backing
>> bean action
>>>> or do you only look
>>>>> at the database? If JPA is involved, then the
>> jpa
>>>> provider may replace
>>>>> null with empty strings (known issue on
>> oracle).
>>>>>
>>>>> LieGrue,
>>>>> strub
>>>>>
>>>>> --- On Mon, 1/10/11, Marsman<ma...@gmx.de>
>>>> wrote:
>>>>>
>>>
>>>
>>
>> --
>> View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30634470.html
>> Sent from the MyFaces - Users mailing list archive at
>> Nabble.com.
>>
>>
>
>
>
>
Re: How to persist null values with JSF2?
Posted by Mark Struberg <st...@yahoo.de>.
nope, I found the tomcat 7 EL to be buggy back when I did need it (should re-evaluate it soon) and use juel now [1]
LieGrue,
strub
[1] https://github.com/struberg/juel
--- On Mon, 1/10/11, Marsman <ma...@gmx.de> wrote:
> From: Marsman <ma...@gmx.de>
> Subject: Re: How to persist null values with JSF2?
> To: users@myfaces.apache.org
> Date: Monday, January 10, 2011, 2:59 PM
>
> After googling another 2 hours I found the solution: Since
> tomcat 6.0.16 we
> have to add the org.apache.el.parser.COERCE_TO_ZERO=false
> VM argument.
> @Strub: Did you have set this VM argument too?
>
> For more infos:
> http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jsf.html#EmptyToNullConverter
> EmptyToNullConverter
>
>
>
> struberg wrote:
> >
> > Hmm, works perfectly over here when adding the
> following to web.xml:
> > <context-param>
> >
> >
> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
> >
> <param-value>true</param-value>
> > </context-param>
> >
> > as Jakob already suggested.
> >
> > LieGrue,
> > strub
> >
> > --- On Mon, 1/10/11, Marsman <ma...@gmx.de>
> wrote:
> >
> >> From: Marsman <ma...@gmx.de>
> >> Subject: Re: How to persist null values with
> JSF2?
> >> To: users@myfaces.apache.org
> >> Date: Monday, January 10, 2011, 1:52 PM
> >>
> >>
> >> The action on the commandButton calls a
> save()-Method in my
> >> backing bean. At
> >> this point, I got the empty fields instead of
> null. You can
> >> see this in my
> >> initial post. I'm using JPA with Hibernate.
> >>
> >> Titus
> >>
> >>
> >>
> >> struberg wrote:
> >> >
> >> > Did you do your debugging in your backing
> bean action
> >> or do you only look
> >> > at the database? If JPA is involved, then the
> jpa
> >> provider may replace
> >> > null with empty strings (known issue on
> oracle).
> >> >
> >> > LieGrue,
> >> > strub
> >> >
> >> > --- On Mon, 1/10/11, Marsman <ma...@gmx.de>
> >> wrote:
> >> >
> >
> >
>
> --
> View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30634470.html
> Sent from the MyFaces - Users mailing list archive at
> Nabble.com.
>
>
Re: How to persist null values with JSF2?
Posted by Marsman <ma...@gmx.de>.
After googling another 2 hours I found the solution: Since tomcat 6.0.16 we
have to add the org.apache.el.parser.COERCE_TO_ZERO=false VM argument.
@Strub: Did you have set this VM argument too?
For more infos:
http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jsf.html#EmptyToNullConverter
EmptyToNullConverter
struberg wrote:
>
> Hmm, works perfectly over here when adding the following to web.xml:
> <context-param>
>
> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
> <param-value>true</param-value>
> </context-param>
>
> as Jakob already suggested.
>
> LieGrue,
> strub
>
> --- On Mon, 1/10/11, Marsman <ma...@gmx.de> wrote:
>
>> From: Marsman <ma...@gmx.de>
>> Subject: Re: How to persist null values with JSF2?
>> To: users@myfaces.apache.org
>> Date: Monday, January 10, 2011, 1:52 PM
>>
>>
>> The action on the commandButton calls a save()-Method in my
>> backing bean. At
>> this point, I got the empty fields instead of null. You can
>> see this in my
>> initial post. I'm using JPA with Hibernate.
>>
>> Titus
>>
>>
>>
>> struberg wrote:
>> >
>> > Did you do your debugging in your backing bean action
>> or do you only look
>> > at the database? If JPA is involved, then the jpa
>> provider may replace
>> > null with empty strings (known issue on oracle).
>> >
>> > LieGrue,
>> > strub
>> >
>> > --- On Mon, 1/10/11, Marsman <ma...@gmx.de>
>> wrote:
>> >
>
>
--
View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30634470.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How to persist null values with JSF2?
Posted by Mark Struberg <st...@yahoo.de>.
Hmm, works perfectly over here when adding the following to web.xml:
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
as Jakob already suggested.
LieGrue,
strub
--- On Mon, 1/10/11, Marsman <ma...@gmx.de> wrote:
> From: Marsman <ma...@gmx.de>
> Subject: Re: How to persist null values with JSF2?
> To: users@myfaces.apache.org
> Date: Monday, January 10, 2011, 1:52 PM
>
>
> The action on the commandButton calls a save()-Method in my
> backing bean. At
> this point, I got the empty fields instead of null. You can
> see this in my
> initial post. I'm using JPA with Hibernate.
>
> Titus
>
>
>
> struberg wrote:
> >
> > Did you do your debugging in your backing bean action
> or do you only look
> > at the database? If JPA is involved, then the jpa
> provider may replace
> > null with empty strings (known issue on oracle).
> >
> > LieGrue,
> > strub
> >
> > --- On Mon, 1/10/11, Marsman <ma...@gmx.de>
> wrote:
> >
> >> From: Marsman <ma...@gmx.de>
> >> Subject: Re: How to persist null values with
> JSF2?
> >> To: users@myfaces.apache.org
> >> Date: Monday, January 10, 2011, 9:48 AM
> >>
> >> I've also set this context parameter to true, but
> entity
> >> properties are not
> >> set to null. I got empty strings and 0 again.
> After that,
> >> I've downloaded a
> >> small JSF 2 example and deployed it. I got the
> same problem
> >> again. With
> >> MyFaces 2.0.3 and Tomcat 6.0.29. What am I doing
> wrong?
> >> :-(
> >>
> >> Titus
> >>
> >>
> >>
> >>
> >> Jakob Korherr wrote:
> >> >
> >> > Hi,
> >> >
> >> > As for JSF 2.0, setting
> >> >
> >>
> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
> >> to true
> >> > should do the trick.
> >> >
> >> > I just tested it with MyFaces 2.0.3 and it
> worked fine
> >> (for both
> >> > String and Integer properties).
> >> >
> >> > Regards,
> >> > Jakob
> >> >
> >> > 2011/1/8 Marsman <ma...@gmx.de>:
> >> >>
> >> >> Hi!
> >> >>
> >> >> Since migrated my application to JSF 2
> I'm no able
> >> to persist an empty to
> >> >> null converted value in the database. The
> values
> >> passed in
> >> >> managedBean.setModel(model) are empty
> strings for
> >> example again. I'm
> >> >> looking
> >> >> for a reason of this behaviour for a few
> days now
> >> and would be happy, if
> >> >> anybody can help me. Here are some
> snippets of my
> >> code:
> >> >>
> >> >> ...
> >> >>
> >> >> Titus
> >> >>
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
> >> >> Sent from the MyFaces - Users mailing
> list archive
> >> at Nabble.com.
> >> >>
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Jakob Korherr
> >> >
> >> > blog: http://www.jakobk.com
> >> > twitter: http://twitter.com/jakobkorherr
> >> > work: http://www.irian.at
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30632274.html
> >> Sent from the MyFaces - Users mailing list archive
> at
> >> Nabble.com.
> >>
> >>
> >
> >
> >
> >
> >
>
> --
> View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30633911.html
> Sent from the MyFaces - Users mailing list archive at
> Nabble.com.
>
>
Re: How to persist null values with JSF2?
Posted by Marsman <ma...@gmx.de>.
The action on the commandButton calls a save()-Method in my backing bean. At
this point, I got the empty fields instead of null. You can see this in my
initial post. I'm using JPA with Hibernate.
Titus
struberg wrote:
>
> Did you do your debugging in your backing bean action or do you only look
> at the database? If JPA is involved, then the jpa provider may replace
> null with empty strings (known issue on oracle).
>
> LieGrue,
> strub
>
> --- On Mon, 1/10/11, Marsman <ma...@gmx.de> wrote:
>
>> From: Marsman <ma...@gmx.de>
>> Subject: Re: How to persist null values with JSF2?
>> To: users@myfaces.apache.org
>> Date: Monday, January 10, 2011, 9:48 AM
>>
>> I've also set this context parameter to true, but entity
>> properties are not
>> set to null. I got empty strings and 0 again. After that,
>> I've downloaded a
>> small JSF 2 example and deployed it. I got the same problem
>> again. With
>> MyFaces 2.0.3 and Tomcat 6.0.29. What am I doing wrong?
>> :-(
>>
>> Titus
>>
>>
>>
>>
>> Jakob Korherr wrote:
>> >
>> > Hi,
>> >
>> > As for JSF 2.0, setting
>> >
>> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
>> to true
>> > should do the trick.
>> >
>> > I just tested it with MyFaces 2.0.3 and it worked fine
>> (for both
>> > String and Integer properties).
>> >
>> > Regards,
>> > Jakob
>> >
>> > 2011/1/8 Marsman <ma...@gmx.de>:
>> >>
>> >> Hi!
>> >>
>> >> Since migrated my application to JSF 2 I'm no able
>> to persist an empty to
>> >> null converted value in the database. The values
>> passed in
>> >> managedBean.setModel(model) are empty strings for
>> example again. I'm
>> >> looking
>> >> for a reason of this behaviour for a few days now
>> and would be happy, if
>> >> anybody can help me. Here are some snippets of my
>> code:
>> >>
>> >> ...
>> >>
>> >> Titus
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
>> >> Sent from the MyFaces - Users mailing list archive
>> at Nabble.com.
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Jakob Korherr
>> >
>> > blog: http://www.jakobk.com
>> > twitter: http://twitter.com/jakobkorherr
>> > work: http://www.irian.at
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30632274.html
>> Sent from the MyFaces - Users mailing list archive at
>> Nabble.com.
>>
>>
>
>
>
>
>
--
View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30633911.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How to persist null values with JSF2?
Posted by Mark Struberg <st...@yahoo.de>.
Did you do your debugging in your backing bean action or do you only look at the database? If JPA is involved, then the jpa provider may replace null with empty strings (known issue on oracle).
LieGrue,
strub
--- On Mon, 1/10/11, Marsman <ma...@gmx.de> wrote:
> From: Marsman <ma...@gmx.de>
> Subject: Re: How to persist null values with JSF2?
> To: users@myfaces.apache.org
> Date: Monday, January 10, 2011, 9:48 AM
>
> I've also set this context parameter to true, but entity
> properties are not
> set to null. I got empty strings and 0 again. After that,
> I've downloaded a
> small JSF 2 example and deployed it. I got the same problem
> again. With
> MyFaces 2.0.3 and Tomcat 6.0.29. What am I doing wrong?
> :-(
>
> Titus
>
>
>
>
> Jakob Korherr wrote:
> >
> > Hi,
> >
> > As for JSF 2.0, setting
> >
> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
> to true
> > should do the trick.
> >
> > I just tested it with MyFaces 2.0.3 and it worked fine
> (for both
> > String and Integer properties).
> >
> > Regards,
> > Jakob
> >
> > 2011/1/8 Marsman <ma...@gmx.de>:
> >>
> >> Hi!
> >>
> >> Since migrated my application to JSF 2 I'm no able
> to persist an empty to
> >> null converted value in the database. The values
> passed in
> >> managedBean.setModel(model) are empty strings for
> example again. I'm
> >> looking
> >> for a reason of this behaviour for a few days now
> and would be happy, if
> >> anybody can help me. Here are some snippets of my
> code:
> >>
> >> ...
> >>
> >> Titus
> >>
> >>
> >> --
> >> View this message in context:
> >> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
> >> Sent from the MyFaces - Users mailing list archive
> at Nabble.com.
> >>
> >>
> >
> >
> >
> > --
> > Jakob Korherr
> >
> > blog: http://www.jakobk.com
> > twitter: http://twitter.com/jakobkorherr
> > work: http://www.irian.at
> >
> >
>
> --
> View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30632274.html
> Sent from the MyFaces - Users mailing list archive at
> Nabble.com.
>
>
Re: How to persist null values with JSF2?
Posted by Marsman <ma...@gmx.de>.
I've also set this context parameter to true, but entity properties are not
set to null. I got empty strings and 0 again. After that, I've downloaded a
small JSF 2 example and deployed it. I got the same problem again. With
MyFaces 2.0.3 and Tomcat 6.0.29. What am I doing wrong? :-(
Titus
Jakob Korherr wrote:
>
> Hi,
>
> As for JSF 2.0, setting
> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL to true
> should do the trick.
>
> I just tested it with MyFaces 2.0.3 and it worked fine (for both
> String and Integer properties).
>
> Regards,
> Jakob
>
> 2011/1/8 Marsman <ma...@gmx.de>:
>>
>> Hi!
>>
>> Since migrated my application to JSF 2 I'm no able to persist an empty to
>> null converted value in the database. The values passed in
>> managedBean.setModel(model) are empty strings for example again. I'm
>> looking
>> for a reason of this behaviour for a few days now and would be happy, if
>> anybody can help me. Here are some snippets of my code:
>>
>> ...
>>
>> Titus
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>
>
--
View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30632274.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How to persist null values with JSF2?
Posted by Jakob Korherr <ja...@gmail.com>.
Hi,
As for JSF 2.0, setting
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL to true
should do the trick.
I just tested it with MyFaces 2.0.3 and it worked fine (for both
String and Integer properties).
Regards,
Jakob
2011/1/8 Marsman <ma...@gmx.de>:
>
> Hi!
>
> Since migrated my application to JSF 2 I'm no able to persist an empty to
> null converted value in the database. The values passed in
> managedBean.setModel(model) are empty strings for example again. I'm looking
> for a reason of this behaviour for a few days now and would be happy, if
> anybody can help me. Here are some snippets of my code:
>
> <h:form id="editAlbum">
> ...
> <h:inputText id="year"
> value="#{albumDetailBean.album.year}"></h:inputText>
> <h:commandButton action="#{albumDetailBean.save}"
> value="#{msg.buttonSave}"></h:commandButton>
> </h:form>
>
> @Entity
> public class Album {
> ...
> @Column
> Integer year;
> ...
> }
>
> @ManagedBean
> @SessionScoped
> public class AlbumDetailBean {
>
> @ManagedProperty(value="#{albumService}")
> private AlbumService albumService;
>
> private Album album;
>
> public static AlbumDetailBean getInstance() {
> FacesContext fc = FacesContext.getCurrentInstance();
> return (AlbumDetailBean) fc.getApplication().evaluateExpressionGet(fc,
> "#{albumDetailBean}", AlbumDetailBean.class);
> }
>
> public String save() {
> // At this point, album.year is Integer(0) instead of null...!
> if (album.getId() == null)
> albumService.insert(album);
> else
> albumService.update(album);
> return "success";
> }
>
> public Album getAlbum() {
> return album;
> }
>
> public void setAlbum(Album album) {
> this.album = album;
> }
> }
>
> I've tried to implement an empty string to null converter and git the same
> behaviour. I've even tried the new
> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL property.
> Without success. :-(
>
> Titus
>
>
> --
> View this message in context: http://old.nabble.com/How-to-persist-null-values-with-JSF2--tp30622750p30622750.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at