0 Replies Latest reply on Jul 27, 2009 6:09 PM by Andrew Lowcock

    Avoiding {or electing} to update a specific field in EntityHome

    Andrew Lowcock Newbie

      I have used seam-gen to create a basic application, and modified it to allow the upload of images into the database.

      This works for both insert and update as expected. Howeverm functionally if no replacement image is provided, the the EntityHome updates the field to 0 length. I understand why, but I am struggling to find a way to amend the UDPATE query to avoid this.

      Can anyone suggest how to do this? I was looking to override update in the entityhome, but I don't understand how to stop a field being updated

      Thanks in advance.

      <s:decorate id="photoField" template="/admin/layout/edit.xhtml">
           <ui:define name="label">Photo</ui:define>
                <s:fileUpload id="file" 
                 fileSize="#{boardHome.instance.photoSize}" />
      <s:decorate id="photoContentTypeField" template="/admin/layout/edit.xhtml" rendered="#{not empty boardHome.instance.photoContentType}">
        <ui:define name="label">photoContentType</ui:define>
          <h:outputText id="photoContentType"
      <a:support event="onblur" reRender="photoContentTypeField" bypassUpdates="true" ajaxSingle="true"/>

      and the Class

      public class Board implements Serializable
           private static Calendar birth;
           private static Calendar today;
           static {
                birth = new GregorianCalendar();
                today = new GregorianCalendar();          
           @Id @GeneratedValue
          private Long id;
           @Length(max = 100)
          private String fullName;
           @Length(max = 100)
           private String jobTitle;
          private Date dateOfBirth;
          private String biography;    
          @Column(name = "photo_data")
          private byte[] photo;     
          @Column(name = "photo_content_type")
          private String photoContentType;
          @Column(name = "photo_size")
           private long photoSize;
          @Column(name= "phto_filename")
          private String photoFileName;
          private Integer order;
          public Long getId() {
              return id;
          public void setId(Long id) {
              this.id = id;
          public String getFullName() {
              return fullName;
          public void setFullName(String fullName) {
              this.fullName = fullName;
          public String getJobTitle() {
                return jobTitle;
           public void setJobTitle(String jobTitle) {
                this.jobTitle = jobTitle;
           public Date getDateOfBirth() {
                return dateOfBirth;
           public void setDateOfBirth(Date dateOfBirth) {
                this.dateOfBirth = dateOfBirth;
           public String getBiography() {
                return biography;
           public void setBiography(String biography) {
                this.biography = biography;
          public byte[] getPhoto() { return photo; }
          public void setPhoto(byte[] photo) { this.photo = photo; }
          public String getPhotoContentType() { return photoContentType; }
          public void setPhotoContentType(String photoContentType) {
              this.photoContentType = photoContentType;
           public long getPhotoSize() { return this.photoSize; }
           public void setPhotoSize(long photoSize) { this.photoSize = photoSize; }
          public String getPhotoFileName() {
                return photoFileName;
           public void setPhotoFileName(String photoFileName) {
                this.photoFileName = photoFileName;
          public Integer getOrder() {
              return order;
          public void setOrder(Integer order) {
              this.order = order;
          public int getAge()
               //to correctly calculate age when birthday has not been yet celebrated
              int factor = 0; 
              today.setTime(new Date());
              // check if birthday has been celebrated this year
              if(today.get(Calendar.DAY_OF_YEAR) < birth.get(Calendar.DAY_OF_YEAR)) {
                   //birthday not celebrated  
                   factor = -1; 
              return today.get(Calendar.YEAR) - birth.get(Calendar.YEAR) + factor;

      Apologies - I am very new to SEAM (3 days into my first application) and 1/2 way though the SiA book (which is highlyrecommended).