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.

Reply via email to