You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Will Martinez A." <wc...@hotmail.com> on 2010/08/11 08:05:25 UTC

problem with wicket + spring + hibernate

Hello,
I'm newbie with wicket,  I'm trying to set up a new project, I took some configuration examples from 5 days of wicket, but I don't know what happened, for some reason I'm not able to save my data, I'm using spring annotations, my application begins with a login form, after that it shows an Add Client form, when I hit the save button, nothing happen, not message, nothing at all.  If somebody can help I will apreciate it a lot. Below you can see my project's files:

************************************************************************************************************************
web.xml 
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
 
    <display-name>scfsi3</display-name>
    <filter>
        <filter-name>wicket.scfsi3</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationFactoryClassName</param-name>
            <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>wicket.scfsi3</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
       <filter-name>open.hibernate.session.in.view</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>

    <!-- Important! This filter mapping must come before Wicket's! -->
    <filter-mapping>
       <filter-name>open.hibernate.session.in.view</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
       <filter-name>wicket.session</filter-name>
       <filter-class>org.apache.wicket.protocol.http.servlet.WicketSessionFilter</filter-class>
       <init-param>
           <param-name>filterName</param-name>
           <param-value>wicket.scfsi3</param-value>
       </init-param>
    </filter>
    <filter-mapping>
        <filter-name>wicket.session</filter-name>
        <url-pattern>/servlet/*</url-pattern>
    </filter-mapping>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:com/fmorales/scfsi3/spring/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

************************************************************************************************************************
my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.fmorales</groupId>
    <artifactId>scfsi3</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <!-- TODO project name  -->
    <name>fmorales</name>
    <description></description>

    <!-- TODO
        <organization>
        <name>company name</name>
        <url>company url</url>
        </organization>
    -->

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
   
     <dependencies>
                <!--  WICKET DEPENDENCIES -->
                <dependency>
                    <groupId>org.apache.wicket</groupId>
                    <artifactId>wicket</artifactId>
                    <version>${wicket.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.wicket</groupId>
                    <artifactId>wicket-extensions</artifactId>
                    <version>${wicket.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.wicket</groupId>
                    <artifactId>wicket-ioc</artifactId>
                    <version>${wicket.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.wicket</groupId>
                    <artifactId>wicket-spring</artifactId>
                    <version>${wicket.version}</version>
                </dependency>
                <!--  HIBERNATE DEPENDNECIES -->
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-annotations</artifactId>
                    <version>${hibernate.version}</version>
                </dependency>
                <dependency>
                    <groupId>c3p0</groupId>
                    <artifactId>c3p0</artifactId>
                    <version>${c3p0.version}</version>
                </dependency>
                <dependency>
                    <groupId>postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgres.version}</version>
                </dependency>
                <dependency>
                    <groupId>javax.transaction</groupId>
                    <artifactId>jta</artifactId>
                    <version>${jta.version}</version>
                </dependency>
                <dependency>
                    <groupId>commons-dbcp</groupId>
                    <artifactId>commons-dbcp</artifactId>
                    <version>${dbcp.version}</version>
                </dependency>
                <!-- SPRING DEPENDENCIES -->
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-test</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-tx</artifactId>
                    <version>${spring.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-core</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-context</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-beans</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>

                <!-- Hazelcast Dependencies -->
                <dependency>
                    <groupId>com.hazelcast</groupId>
                    <artifactId>hazelcast</artifactId>
                    <version>${hazelcast.version}</version>
                </dependency>

                <!-- TWITTER4J DEPENDENCIES -->
                <dependency>
                   <groupId>net.homeip.yusuke</groupId>
                   <artifactId>twitter4j</artifactId>
                   <version>2.0.8</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.slf4j</groupId>
                            <artifactId>nlog4j</artifactId>
                        </exclusion>
                    </exclusions>
               </dependency>

                <!-- JETS3T DEPENDENCIES -->
                <dependency>
                    <groupId>net.java.dev.jets3t</groupId>
                    <artifactId>jets3t</artifactId>
                    <version>0.7.1</version>
                </dependency>

                <!-- LOGGING DEPENDENCIES - LOG4J -->
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                    <version>${slf4j.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                    <version>${slf4j.version}</version>
                </dependency>
        <!--
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>${log4j.version}</version>
                </dependency>
        -->

                <!--  JUNIT DEPENDENCY FOR TESTING -->
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>${junit.version}</version>
                    <scope>test</scope>
                </dependency>

                <!-- EasyMock for test cases -->

                <dependency>
                    <groupId>org.easymock</groupId>
                    <artifactId>easymock</artifactId>
                    <version>2.4</version>
                </dependency>

                <dependency>
                    <groupId>org.easymock</groupId>
                    <artifactId>easymockclassextension</artifactId>
                    <version>2.4</version>
                </dependency>

                <dependency>
                    <groupId>org.dbunit</groupId>
                    <artifactId>dbunit</artifactId>
                    <version>2.2</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.unitils</groupId>
                    <artifactId>unitils</artifactId>
                    <version>1.0</version>
                </dependency>

                <dependency>
                    <groupId>hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>1.8.0.7</version>
                </dependency>

                <!--  JETTY DEPENDENCIES FOR TESTING  -->
                <dependency>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty</artifactId>
                    <version>${jetty.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-util</artifactId>
                    <version>${jetty.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-management</artifactId>
                    <version>${jetty.version}</version>
                    <scope>provided</scope>
                </dependency>

                <!-- RESTEASY DEPENDENCIES -->
                <dependency>
                    <groupId>org.jboss.resteasy</groupId>
                    <artifactId>resteasy-jaxrs</artifactId>
                    <version>${resteasy.version}</version>
                </dependency>
            </dependencies>

  

    
    <build>
        <filters>
            <filter>src/main/filters/filters-${env}.properties</filter>
        </filters>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
                    
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                 <configuration>
                   <source>1.6</source>
                   <target>1.6</target>
                 </configuration>
            </plugin>           
        </plugins>
    </build>
   
      <properties>
        <wicket.version>1.4.0</wicket.version>
        <jetty.version>6.1.4</jetty.version>
        <spring.version>2.5.5</spring.version>
        <hibernate.version>3.4.0.GA</hibernate.version>
        <c3p0.version>0.9.1.2</c3p0.version>
        <junit.version>4.5</junit.version>
        <postgres.version>8.3-603.jdbc4</postgres.version>
        <commons-lang.version>2.4</commons-lang.version>
        <javamail.version>1.4.1</javamail.version>
        <commons-fileupload.version>1.2.1</commons-fileupload.version>
        <jta.version>1.0.1B</jta.version>
        <dbcp.version>1.2.2</dbcp.version>
        <slf4j.version>1.4.2</slf4j.version>
        <log4j.version>1.2.14</log4j.version>
        <easymock.version>2.4</easymock.version>
        <resteasy.version>1.0.2.GA</resteasy.version>
        <hazelcast.version>1.7.1</hazelcast.version>
    <!-- default env when no profile is specified -->
        <env>DEV</env>
    </properties>
    <profiles>
        <profile>
            <id>DEV</id>
            <properties>
                <env>DEV</env>
            </properties>
        </profile>
    
        <profile>
            <id>QA</id>
            <properties>
                <env>QA</env>
            </properties>
        </profile>

        <profile>
            <id>PROD</id>
            <properties>
                <env>PROD</env>
            </properties>
        </profile>
    </profiles>
</project>

************************************************************************************************************************
applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


 
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:application.properties</value>
            </list>
        </property>
        <property name="ignoreResourceNotFound" value="true"/>
    </bean>

    <!-- DAOs -->
    <bean id="clienteDao" class="com.fmorales.dao.ClienteDao">
          <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <bean id="wicketApplication" class="com.fmorales.FMoralesApplication" />
        
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName">
            <value>${jdbc.driver}</value>
        </property>
        <property name="url">
            <value>${jdbc.url}</value>
        </property>
        <property name="username">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
    </bean>
 
     <!-- hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">hibernate.show_sql</prop>
                <prop key="use_outer_join">${hibernate.use_outer_join}</prop>
                
                <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                <prop key="hibernate.cache.provider_class">${hibernate.cache.provider}</prop>
                
                <prop key="hibernate.connection.pool_size">10</prop>
                <prop key="hibernate.jdbc.batch_size">1000</prop>
                <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
            </props>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.fmorales.domain.Cliente</value>
            </list>
        </property>
         <property name="schemaUpdate" value="${hibernate.schemaUpdate}"/> 
    </bean>
    
    <tx:annotation-driven/>
        <!-- setup transaction manager  -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

************************************************************************************************************************
Cliente.java(Domain class)

package com.fmorales.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * Entidad Cliente.
 *
 */
@Entity
@Table(name = "cl_clientes")
@SequenceGenerator(name = "cliente_id_seq", sequenceName = "cliente_id_seq")
public class Cliente implements Serializable{
    private static final long serialVersionUID = 1L;
    @Override
        public boolean equals(final Object object) {
            final boolean equals;
            if (false == (object instanceof Cliente)) {
                equals = false;
            }
            else
            if (this == object) {
                equals = true;
            }
            else {
                final Cliente other = (Cliente) object;
                equals = new EqualsBuilder()
                    .append(getApellido1(),other.getApellido1())
                    .append(getApellido2(),other.getApellido2())
                    .append(getCelular(),other.getCelular())
                    .append(getContacto(),other.getContacto())
                    .append(getDireccion(),other.getDireccion())
                    .append(getDocCte(),other.getDocCte())
                    .append(getEjecutivo(),other.getEjecutivo())
                    .append(getEmail(),other.getEmail())
                    .append(getFecIng(),other.getFecIng())
                    .append(getFecMod(),other.getFecMod())
                    .append(getIdCliente(),other.getIdCliente())
                    .append(getIdContacto(),other.getIdContacto())
                    .append(getNombre(),other.getNombre())
                    .append(getObservaciones(),other.getObservaciones())
                    .append(getTelefono(),other.getTelefono())
                    .append(getTipoDoc(),other.getTipoDoc())
                    .append(getTipoPersona(),other.getTipoPersona())
                    .append(getUsuario(),other.getUsuario())
                    .isEquals();
            }
            return equals;
        }
      
        @Override
        public int hashCode() {
            return new HashCodeBuilder()
            .append(getApellido1())
            .append(getApellido2())
            .append(getCelular())
            .append(getContacto())
            .append(getDireccion())
            .append(getDocCte())
            .append(getEjecutivo())
            .append(getEmail())
            .append(getFecIng())
            .append(getFecMod())
            .append(getIdCliente())
            .append(getIdContacto())
            .append(getNombre())
            .append(getObservaciones())
            .append(getTelefono())
            .append(getTipoDoc())
            .append(getTipoPersona())
            .append(getUsuario())
            .toHashCode();
        }

     /**
      * Propiedad para el manejo del bloqueo.
      */
     @Version
     @Column(nullable = false)
     private Integer version;
     
     @Id
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cliente_id_seq")
     @Column(name = "cl_id_cliente", nullable = false)
     private Long idCliente;
    
     @Basic
     @Column(name="cl_doc_cte", length = 20)
     private String docCte;
     
     @Basic
     @Column(name="cl_tipo_doc", length = 10)
     private String tipoDoc;
     
     @Basic
     @Column(name="cl_nombre", length = 50)
     private String nombre;
      
     @Basic
     @Column(name="cl_apellido1", length = 20)
     private String apellido1;
     
     @Basic
     @Column(name="cl_apellido2", length = 20)
     private String apellido2;
     
     @Basic
     @Column(name="cl_direccion", length = 150)
     private String direccion;
     
       @Basic
     @Column(name="cl_telefono")
     private String telefono;
      
     @Basic
     @Column(name="cl_email")
     private String email;
     
     @Basic
     @Column(name="cl_celular")
     private String celular;
     
     @Basic
     @Column(name="cl_observaciones")
     private String observaciones;
     
     @Basic
     @Column(name="cl_ir")
     private boolean ir;

     @Basic
     @Column(name="cl_tipo_persona")
     private String tipoPersona;

     @Basic
     @Column(name="cl_contacto")
     private String contacto;

     @Basic
     @Column(name="cl_fec_ing")
     private Calendar fecIng;

     @Basic
     @Column(name="cl_id_contacto")
     private Long idContacto;
     
     @Basic
     @Column(name="cl_ejecutivo")
     private Long ejecutivo;

     @Basic
     @Column(name="cl_fec_mod")
     private Calendar fecMod;

     @Basic
     @Column(name="cl_usuario")
     private String usuario;

    public Long getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Long idCliente) {
        this.idCliente = idCliente;
    }

    public String getDocCte() {
        return docCte;
    }

    public void setDocCte(String docCte) {
        this.docCte = docCte;
    }

    public String getTipoDoc() {
        return tipoDoc;
    }

    public void setTipoDoc(String tipoDoc) {
        this.tipoDoc = tipoDoc;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getApellido1() {
        return apellido1;
    }

    public void setApellido1(String apellido1) {
        this.apellido1 = apellido1;
    }

    public String getApellido2() {
        return apellido2;
    }

    public void setApellido2(String apellido2) {
        this.apellido2 = apellido2;
    }

    public String getDireccion() {
        return direccion;
    }

    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public String getTelefono() {
        return telefono;
    }

    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCelular() {
        return celular;
    }

    public void setCelular(String celular) {
        this.celular = celular;
    }

    public String getObservaciones() {
        return observaciones;
    }

    public void setObservaciones(String observaciones) {
        this.observaciones = observaciones;
    }

    public boolean isIr() {
        return ir;
    }

    public void setIr(boolean ir) {
        this.ir = ir;
    }

    public String getTipoPersona() {
        return tipoPersona;
    }

    public void setTipoPersona(String tipoPersona) {
        this.tipoPersona = tipoPersona;
    }

    public String getContacto() {
        return contacto;
    }

    public void setContacto(String contacto) {
        this.contacto = contacto;
    }

    public Calendar getFecIng() {
        return fecIng;
    }

    public void setFecIng(Calendar fecIng) {
        this.fecIng = fecIng;
    }

    public Long getIdContacto() {
        return idContacto;
    }

    public void setIdContacto(Long idContacto) {
        this.idContacto = idContacto;
    }

    public Long getEjecutivo() {
        return ejecutivo;
    }

    public void setEjecutivo(Long ejecutivo) {
        this.ejecutivo = ejecutivo;
    }

    public Calendar getFecMod() {
        return fecMod;
    }

    public void setFecMod(Calendar fecMod) {
        this.fecMod = fecMod;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }
    
    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }
}

************************************************************************************************************************

Dao
package com.fmorales.dao;

import java.util.List;

import org.hibernate.Transaction;
import org.springframework.transaction.annotation.Transactional;

import com.fmorales.domain.Cliente;
import com.fmorales.hibernate.AbstractDaoHibernate;

public class ClienteDao extends AbstractDaoHibernate<Cliente> 
implements IClienteDao {
    

    public ClienteDao() {
        super(Cliente.class);
    }

    public List<Cliente> findByName(final String clientName) {
        List<Cliente> clientes = null;
        getSession()
        .createQuery("From Cliente a Where a.name like :name")
        .setString("name", clientName+"%")
        .list();
        return clientes;
    }

    public Cliente getCliente(final Long id) {
        Cliente cliente = (Cliente) getSession()
        .createQuery("From Cliente a Where a.id = :id")
        .setLong("id", id)
        .uniqueResult();
        return cliente;
    }
    
    public Long setCliente(Cliente cliente) {
        save(cliente);
        return cliente.getIdCliente();
    }
}
************************************************************************************************************************
AbstractDaoHibernate

package com.fmorales.hibernate;


import org.springframework.orm.hibernate3.support.HibernateDaoSupport;



public class AbstractDaoHibernate<T> extends HibernateDaoSupport {

    // MEMBERS

    private Class entityClass;

    // CONSTRUCTORS

    protected AbstractDaoHibernate(Class dataClass) {
        super();
        this.entityClass = dataClass;
    }

    // METHODS

    @SuppressWarnings("unchecked")
    private T load(Long id) {
        return (T) getSession().get(entityClass, id);
    }

    @SuppressWarnings("unchecked")
    private T loadChecked(Long id) throws EntityNotFoundException {
        T persistedObject = load(id);

        if (persistedObject == null) {
            throw new EntityNotFoundException(entityClass, id);
        }

        return persistedObject;
    }

    public void merge(T detachedObject) {
        getSession().merge(detachedObject);
    }

    public void save(T persistedObject) {
        getSession().saveOrUpdate(persistedObject);
    }

    private void delete(T persistedObject) {
        getSession().delete(persistedObject);
    }

    public void delete(Long id) {
        delete(loadChecked(id));
    }

}

************************************************************************************************************************
AgregarCliente(page call from Login)

package com.fmorales.scfsi3.web.pages.catalogo;

import java.util.Arrays;
import java.util.Calendar;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;


import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.fmorales.dao.ClienteDao;
import com.fmorales.domain.Cliente;


public class AgregarCliente extends WebPage {
    @SpringBean
    ClienteDao clienteDao;

    private String userId;
    private Long idCliente;
    private String docCte;
    private String tipoDoc;
    private String nombre;
    private String apellido1;
    private String apellido2;
    private String direccion;
    private String telefono;
    private String email;
    private String celular;
    private String observaciones;
    private boolean ir;
    private String tipoPersona;
    private String contacto;
    private Calendar fecIng;
    private Long idContacto;
    private String ejecutivo;
    private Calendar fecMod;
    private String usuario;


    public AgregarCliente(String userId){
        this.setUserId(userId);
        TextField<Long> idClienteField = new TextField<Long>("idCliente", new PropertyModel<Long>(this,"idCliente"));
        TextField<String> docCteField = new TextField<String>("docCte", new PropertyModel<String>(this,"docCte"));
        docCteField.setRequired(true);
        DropDownChoice tipoDocComb = new DropDownChoice("tipoDoc", new PropertyModel(this,"tipoDoc"), 
        Arrays.asList(new String[]{"Cedula de Identidad","Pasaporte","Cedula de Residencia"}));
        TextField nombreField = new TextField("nombre", new PropertyModel(this,"nombre"));
        nombreField.setRequired(true);
        TextField apellido1Field = new TextField("apellido1", new PropertyModel(this,"apellido1"));
        apellido1Field.setRequired(true);
        TextField apellido2Field = new TextField("apellido2", new PropertyModel(this,"apellido2"));
        TextField direccionField = new TextField("direccion", new PropertyModel(this,"direccion"));
        TextField telefonoField = new TextField("telefono", new PropertyModel(this,"telefono"));
        TextField emailField = new TextField("email", new PropertyModel(this,"email"));
        TextField celularField = new TextField("celular", new PropertyModel(this,"celular"));
        TextArea observacionesField = new TextArea("observaciones", new PropertyModel(this,"observaciones"));
        CheckBox irCheck = new CheckBox("ir", new PropertyModel(this,"ir"));
        DropDownChoice tipoPersonaComb =
            new DropDownChoice("tipoPersona",
                               new PropertyModel(this,"tipoPersona"), 
                               Arrays.asList(new String[]{"Natural","Juridica"}));
        tipoPersonaComb.setRequired(true);
        DropDownChoice ejecutivoComb = new DropDownChoice("ejecutivo", new PropertyModel(this,"ejecutivo"), 
                Arrays.asList(new String[]{"Ejecutivo 1","Ejecutivo 2"}));
        ejecutivoComb.setRequired(true);
        TextField contactoField = new TextField("contacto", new PropertyModel(this,"contacto"));
        
        FeedbackPanel feedback = new FeedbackPanel("feedback");
        //Label feedback = new Label("feedback", new PropertyModel(this,"feedback"));
        
        Form form = new AgregarClienteForm("agregarClienteForm");
        form.add(idClienteField);
        form.add(docCteField);
        form.add(tipoDocComb);
        form.add(nombreField);
        form.add(apellido1Field);
        form.add(apellido2Field);
        form.add(direccionField);
        form.add(telefonoField);
        form.add(emailField);
        form.add(celularField);
        form.add(observacionesField);
        form.add(irCheck);        
        form.add(tipoPersonaComb);
        form.add(ejecutivoComb);
        form.add(contactoField);
        add(feedback);
        add(form);
    }
    class AgregarClienteForm extends Form{
        public AgregarClienteForm(String id){
            super(id);
        }
        @Override
        public void onSubmit() {
            Long idCliente = getIdCliente();
            String docCte = getDocCte();
            String tipoDoc = getTipoDoc();
            String nombre = getNombre();
            String apellido1 = getApellido1();
            String apellido2 = getApellido2();
            String direccion = getDireccion();
            String telefono = getTelefono();
            String email = getEmail();
            String celular = getCelular();
            String observaciones = getObservaciones();
            boolean ir = isIr();
            String tipoPersona = getTipoPersona();
            String contacto = getContacto();
            String ejecutivo = getEjecutivo();
            
            //error(docCte + " "+tipoDoc+" "+nombre);
            
            Cliente cliente = new Cliente();
            if (idCliente != null){
                cliente.setIdCliente(idCliente);
            }
            cliente.setDocCte(docCte);
            cliente.setTipoDoc(tipoDoc);
            cliente.setNombre(nombre);
            cliente.setApellido1(apellido1);
            cliente.setApellido2(apellido2);
            cliente.setDireccion(direccion);
            cliente.setTelefono(telefono);
            cliente.setEmail(email);
            cliente.setCelular(celular);
            cliente.setObservaciones(observaciones);
            cliente.setIr(ir);
            cliente.setTipoPersona(tipoPersona);
            cliente.setContacto(contacto);
            cliente.setEjecutivo((long)1);
            cliente.setUsuario(getUserId());
            Calendar fecha = Calendar.getInstance();
            cliente.setFecIng(fecha);
            cliente.setFecMod(fecha);
            Long idCli = clienteDao.setCliente(cliente);
            System.out.println("idCliente -->"+idCli);
            Cliente cliente2 = clienteDao.getCliente(idCli);
            //error(cliente2.toString());
            
        }
    }

    public Long getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Long idCliente) {
        this.idCliente = idCliente;
    }

    public String getDocCte() {
        return docCte;
    }

    public void setDocCte(String docCte) {
        this.docCte = docCte;
    }

    public String getTipoDoc() {
        return tipoDoc;
    }

    public void setTipoDoc(String tipoDoc) {
        this.tipoDoc = tipoDoc;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getApellido1() {
        return apellido1;
    }

    public void setApellido1(String apellido1) {
        this.apellido1 = apellido1;
    }

    public String getApellido2() {
        return apellido2;
    }

    public void setApellido2(String apellido2) {
        this.apellido2 = apellido2;
    }

    public String getDireccion() {
        return direccion;
    }

    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public String getTelefono() {
        return telefono;
    }

    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCelular() {
        return celular;
    }

    public void setCelular(String celular) {
        this.celular = celular;
    }

    public String getObservaciones() {
        return observaciones;
    }

    public void setObservaciones(String observaciones) {
        this.observaciones = observaciones;
    }

    public boolean isIr() {
        return ir;
    }

    public void setIr(boolean ir) {
        this.ir = ir;
    }

    public String getTipoPersona() {
        return tipoPersona;
    }

    public void setTipoPersona(String tipoPersona) {
        this.tipoPersona = tipoPersona;
    }

    public String getContacto() {
        return contacto;
    }

    public void setContacto(String contacto) {
        this.contacto = contacto;
    }

    public Calendar getFecIng() {
        return fecIng;
    }

    public void setFecIng(Calendar fecIng) {
        this.fecIng = fecIng;
    }

    public Long getIdContacto() {
        return idContacto;
    }

    public void setIdContacto(Long idContacto) {
        this.idContacto = idContacto;
    }

    public String getEjecutivo() {
        return ejecutivo;
    }

    public void setEjecutivo(String ejecutivo) {
        this.ejecutivo = ejecutivo;
    }

    public Calendar getFecMod() {
        return fecMod;
    }

    public void setFecMod(Calendar fecMod) {
        this.fecMod = fecMod;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return userId;
    }

}

************************************************************************************************************************
AgregarCliente.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Agregar/Actualizar Clientes</title>
</head>
<body>
     <!-- Added a span to display feedback --> 
        <span wicket:id = "feedback">
            el mensaje va por aca
        </span>
        <div align="left">        
            <form wicket:id="agregarClienteForm">
               <table border=0 widht=80%>
                   <tbody>
                      <tr>
                          <td>Id Cliente:</td>
                         <td> 
                              <input type="text" wicket:id="idCliente" disabled = "disabled"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Nombres:</td>
                         <td> 
                              <input type="text" wicket:id="nombre"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Primer Apellido: </td>
                         <td> 
                              <input type="text" wicket:id="apellido1"/><br/>
                         </td>
                      </tr>           
                      <tr>
                          <td>Segundo Apellido: </td>
                         <td> 
                              <input type="text" wicket:id="apellido2"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Tipo Documento: </td>
                         <td> 
                              <select wicket:id="tipoDoc">
                                  <option>Cedula de Identidad</option>
                                  <option>Pasaporte</option>
                                  <option>Cedula de Residencia</option>
                              </select><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Numero Documento:</td>
                         <td> 
                              <input type="text" wicket:id="docCte"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Dirección:</td>
                         <td> 
                              <input type="text" wicket:id="direccion"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Telefono :</td>
                         <td> 
                              <input type="text" wicket:id="telefono"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Email:</td>
                         <td> 
                              <input type="text" wicket:id="email"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Celular:</td>
                         <td> 
                              <input type="text" wicket:id="celular"/><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Observaciones:</td>
                         <td> 
                              <textarea name="observa" 
                                        wicket:id="observaciones"
                                        ROWS=4 COLS=23>
                              </textarea><br/>
                         </td>
                      </tr>                     
                      <tr>
                          <td>Excento IR:</td>
                         <td> 
                              <input type="checkbox" wicket:id="ir"/><br/>
                         </td>
                      </tr>
                      <tr>
                      <td>Tipo Persona: </td>
                         <td> 
                              <select wicket:id="tipoPersona">
                                  <option>Narutal</option>
                                  <option>Juridica</option>
                              </select><br/>
                         </td>
                      </tr>
                      <tr>
                          <td>Contacto:</td>
                         <td> 
                              <input type="text" wicket:id="contacto"/><br/>
                         </td>
                         
                      </tr>
                      <tr>
                      <td>Vendedor: </td>
                         <td> 
                              <select wicket:id="ejecutivo">
                                  <option>Ejecutivo 1</option>
                                  <option>Ejecutivo 2</option>
                                  <option>Ejecutivo 3</option>
                              </select><br/>
                         </td>
                      </tr>
                    </tbody>
                </table>
                 <hr>
                    <input type="submit" value="AgregarCliente"/>
            </form>
        </div>
</body>
</html>

************************************************************************************************************************
WebApplication
package com.fmorales;

import javax.servlet.ServletContext;

import org.apache.wicket.application.IComponentInstantiationListener;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 * 
 * @see com.fmorales.Start#main(String[])
 */
public class FMoralesApplication extends WebApplication
{    
    private final Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * Constructor
     */
    public FMoralesApplication()
    {
    }

        @Override
        protected void init() {
            super.init();

            addComponentInstantiationListener(getSpringComponentInjector(this));

            getMarkupSettings().setStripWicketTags(true);

            mountBookmarkablePage("/home", HomePage.class);

            ServletContext servletContext = super.getServletContext();
            applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */

     protected IComponentInstantiationListener getSpringComponentInjector(WebApplication application) {
        return new SpringComponentInjector(application);
     }

     public static FMoralesApplication getInstance() {
        return ((FMoralesApplication) WebApplication.get());
     }

     public Class<Login> getHomePage() {
        return Login.class;
     }

     private ApplicationContext applicationContext;


     public Object getBean(String name) {
        if (name == null) return null;

        return applicationContext.getBean(name);
     }
}

 		 	   		  

Re: SV: problem with wicket + spring + hibernate

Posted by jcgarciam <jc...@gmail.com>.
Probably some Form validation fail (some field cannot be converted), try
overriding the OnError method in the form, report any error in the
feedbackpanel.


On Wed, Aug 11, 2010 at 4:10 AM, Will Martinez A. [via Apache Wicket] <
ml-node+2320816-430238374-65838@n4.nabble.com<ml...@n4.nabble.com>
> wrote:

>
> As I said before "I took some configurations files from 5 days of
> wicket(mysticpaste)" and for mysticpaste it works fine.
>
> I think I found the problem for some reason without @transactional it is
> not working, in mysticpaste it works without @transactional, but in my
> project it need it, some one can tell why?
>
> Thanks,
> Will
>
>
>
> > From: [hidden email]<http://user/SendEmail.jtp?type=node&node=2320816&i=0>
> > To: [hidden email]<http://user/SendEmail.jtp?type=node&node=2320816&i=1>
> > Date: Wed, 11 Aug 2010 08:50:01 +0200
> > Subject: SV: problem with wicket + spring + hibernate
> >
> > I noticed that you ignored the warning here:
> >
> > >     <!-- Important! This filter mapping must come before Wicket's! -->
> >
> > by placing the Wicket filters first.
> >
> > - Tor Iver
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2320816&i=2>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2320816&i=3>
> >
>
>
> ------------------------------
>  View message @
> http://apache-wicket.1842946.n4.nabble.com/problem-with-wicket-spring-hibernate-tp2320778p2320816.html
> To unsubscribe from Apache Wicket, click here<http://apache-wicket.1842946.n4.nabble.com/template/NodeServlet.jtp?tpl=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>.
>
>
>


-- 
Sincerely,
JC (http://www.linkedin.com/in/jcgarciam)
Work smarter, not harder!.

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/problem-with-wicket-spring-hibernate-tp2320778p2321036.html
Sent from the Wicket - User mailing list archive at Nabble.com.

RE: SV: problem with wicket + spring + hibernate

Posted by "Will Martinez A." <wc...@hotmail.com>.
As I said before "I took some configurations files from 5 days of wicket(mysticpaste)" and for mysticpaste it works fine.

I think I found the problem for some reason without @transactional it is not working, in mysticpaste it works without @transactional, but in my project it need it, some one can tell why?

Thanks,
Will



> From: TorIverW@arrive.no
> To: users@wicket.apache.org
> Date: Wed, 11 Aug 2010 08:50:01 +0200
> Subject: SV: problem with wicket + spring + hibernate
> 
> I noticed that you ignored the warning here:
> 
> >     <!-- Important! This filter mapping must come before Wicket's! -->
> 
> by placing the Wicket filters first.
> 
> - Tor Iver
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
 		 	   		  

SV: problem with wicket + spring + hibernate

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
I noticed that you ignored the warning here:

>     <!-- Important! This filter mapping must come before Wicket's! -->

by placing the Wicket filters first.

- Tor Iver

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org