0 Replies Latest reply on Feb 3, 2011 12:43 PM by Romildo Jozue Paiter

    Form duplicate image in DB

    Romildo Jozue Paiter Newbie

      Hello, peaple.

       

      I made a form that takes a file and send it to any bank. But when I register a new item and not send the image, he automatically takes the picture from the previous record and put on record that I just entered.


      Anyone have any ideas??

       

      [code]

      @Name("revenda")

      @Entity

      @Table(name="revenda")

      public class Revenda {

       

          @Id

          @GeneratedValue

          private Long id;

       

          @Column(name="nome_fantasia", nullable=false)

          private String nomeFantasia;

       

          @Lob

          @Column(length = 2147483647)

          @Basic(fetch = FetchType.LAZY)

          private byte[] logomarca;

       

          @Column(name="nome_logomarca")

          private String nomeLogomarca;

          public String getNomeLogomarca() { return this.nomeLogomarca;    }

          public void setNomeLogomarca(String nomeLogomarca) { this.nomeLogomarca = nomeLogomarca; }

       

          @Column(name="tamanho_logomarca", nullable=true)

          private Long size;

          public Long getSize() { return this.size; }

          public void setSize(Long size) { this.size = size; }

       

          @Column(name="content_type")

          private String contentType;

          public String getContentType() { return this.contentType; }

          public void setContentType(String contentType) { this.contentType = contentType; }

      [/code]

       

      [code]

              <h:form id="form" enctype="multipart/form-data">

                  <h:commandLink action="listaRevenda" value="Voltar"

                      styleClass="linkSC" immediate="true" />

       

                  <h:messages />

       

                  <s:decorate id="codigoDecorate" template="display.xhtml"

                      rendered="#{revendaAction.revenda.id != null}">            

                      <ui:define name="label">Código:</ui:define>

                       #{revendaAction.revenda.id}

                      <h:inputText id="id"

                          value="#{revendaAction.revenda.id}" disabled="true" />

                  </s:decorate>

       

                  <s:decorate id="nomeFantasiaDecorate" template="edit.xhtml">

                      <ui:define name="label">Nome Fantasia:</ui:define>

                      <h:inputText id="nomefantasia" value="#{revendaAction.revenda.nomeFantasia}" required="true">

                          <a4j:support id="onblur" event="onblur" reRender="nomeFantasiaDecorate"/>

                      </h:inputText>

                  </s:decorate>

       

                  <s:decorate id="fileUploadDecoration" template="edit.xhtml">

                      <ui:define name="label">Logotipo</ui:define>

                      <s:fileUpload id="logomarca" data="#{revendaAction.revenda.logomarca}"

                                contentType="#{revendaAction.revenda.contentType}"

                                fileName="#{revendaAction.revenda.nomeLogomarca}"

                                />

                  </s:decorate>

       

                  <h:commandButton action="#{revendaAction.salvaRevenda}" value="Salvar" />                                       

              </h:form>

      [/code]

       

      [code]

          /**

           * Função responsavel em salvar uma revenda no

           * Banco de Dados

           *

           * @author Romildo Jozue Paiter

           * @data 25/01/2011

           */

          @End

          public String salvaRevenda(){

              if(revenda.getId() == null){

                  try {

                      em.persist(revenda);

                      facesMessages.addFromResourceBundle("inserirRevendaSucesso");

                  }catch (Exception e) {

                      facesMessages.addFromResourceBundle("inserirRevendaFalha");

                      e.printStackTrace();

                      return null;

                  }

                  return "listaRevenda";

              }else{

                  try {

                      // em.refresh(revenda);

                      em.merge(revenda);

                      facesMessages.addFromResourceBundle("inserirRevendaSucesso");

                  }catch (Exception e) {

                      facesMessages.addFromResourceBundle("inserirRevendaFalha");

                      e.printStackTrace();

                      return null;

                  }

                  return "listaRevenda";           

              }           

          }

      [/code]

       

      components.xml

      [code]

      <?xml version="1.0" encoding="UTF-8"?>

      <components xmlns="http://jboss.com/products/seam/components"

                  xmlns:core="http://jboss.com/products/seam/core"

                  xmlns:persistence="http://jboss.com/products/seam/persistence"

                  xmlns:drools="http://jboss.com/products/seam/drools"

                  xmlns:bpm="http://jboss.com/products/seam/bpm"

                  xmlns:security="http://jboss.com/products/seam/security"

                  xmlns:mail="http://jboss.com/products/seam/mail"

                  xmlns:web="http://jboss.com/products/seam/web"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xsi:schemaLocation=

                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd

                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd

                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd

                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd

                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd

                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd

                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd

                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">

       

            <core:init debug="true" jndi-pattern="@jndiPattern@"/>

       

      <!--   <core:init debug="true" jndi-pattern="SofistCar-ear/#{ejbName}/local"/>-->

       

       

         <core:manager concurrent-request-timeout="500"

                       conversation-timeout="120000"

                       conversation-id-parameter="cid"

                       parent-conversation-id-parameter="pid"/>

       

         <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->

         <web:hot-deploy-filter url-pattern="*.seam"/>

       

         <web:multipart-filter create-temp-files="true"

                            max-request-size="1000000000"

                            url-pattern="*.seam" />

       

        <component class="org.jboss.seam.web.MultipartFilter">

            <property name="createTempFiles">true</property>

            <property name="maxRequestSize">1000000</property>

        </component>

       

         <persistence:managed-persistence-context

              name="entityManager" auto-create="true"

              persistence-unit-jndi-name="java:/SofistCarEntityManagerFactory"/>       

       

         <drools:rule-base name="securityRules">

            <drools:rule-files><value>/security.drl</value></drools:rule-files>

         </drools:rule-base>

       

         <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

       

         <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>

       

         <event type="org.jboss.seam.security.notLoggedIn">

            <action execute="#{redirect.captureCurrentView}"/>

         </event>

         <event type="org.jboss.seam.security.loginSuccessful">

            <action execute="#{redirect.returnToCapturedView}"/>

         </event>

       

         <mail:mail-session host="localhost" port="25"/>

       

         <!-- For use with jBPM pageflow or process management -->

         <!--

         <bpm:jbpm>

            <bpm:process-definitions></bpm:process-definitions>

            <bpm:pageflow-definitions></bpm:pageflow-definitions>

         </bpm:jbpm>

         -->

       

      </components>

      [/code]

       

      Anybody, know de answer, thanks