récupérer les données d'une formulaire

Bonjour;
je suis débutant en spring vaadin
je suis entrain de développer une démo (hibernate spring vaadin)
j’ai fais une fonction d’ajout une formulaire et il est bien marché, et maintenant j’ai un problème d’afficher cette formulaire,
pouvez vous m’aider comment récupérer les données et l’afficher

voila mon application


/**
 * 
 */

package com.businessdecision.service;

import java.util.Calendar;

import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import com.businessdecision.dao.AdministrateurDAO;
import com.businessdecision.entity.Administrateur;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.PortletRequestListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Reindeer;

/**
 * 
 * Class Description;
 * 
 * Copyright: Copyright 2011 Company: Tunisie TradeNet
 * 
 * @author: MEJRI Yassine
 * @version: 1.0
 * 
 *           Modification History: Date Author Description
 *           ----------------------- 28 oct. 2011
 * 
 */
@Configurable(preConstruction = true, autowire = Autowire.BY_NAME)
public class MyApplication extends Application {

	/**
	 *      
	 */
	private static final long serialVersionUID = 1198938441421455822L;

	/** */
	public static Logger trace = Logger.getLogger(MyApplication.class);

	/** */
	@Autowired
	private AdministrateurDAO administrateurDAO;

	@Override
	public void init() {
		// TODO Auto-generated method stub
		trace.info("Initialisation de l'application, date = "
				+ Calendar.getInstance().getTime());
		setTheme("reindeer");

		Window main = new Window("test");
		final TextField login = new TextField("login");
		final TextField mdp = new TextField("mdp");
		final TextField email = new TextField("email");
		main.addComponent(login);
		main.addComponent(mdp);
		main.addComponent(email);

		Button save = new Button("save");
		save.addListener(new ClickListener() {

			
			public void buttonClick(ClickEvent event) {
				Administrateur administrateur = new Administrateur();
				administrateur.setLogin(login.getValue().toString());
				administrateur.setMotPass(mdp.getValue().toString());
				administrateur.setEmail(email.getValue().toString());
				
				administrateurDAO.save(administrateur);
			
				

			}
		});
		main.addComponent(save);

		setMainWindow(main);
	}

	

}

Merci

Hi,

not completely sure what you are trying to do as my French is pretty bad (most of the people on the forum speak English, so you will probably get an answer faster if you ask in English :D)

Anyway, your code looks good. You are creating a form by hand using TextFields. If I understood you correctly you want to set the value for the textfields at some point as well? Or do you not get the whole UI to show at all?

I tried your code and I can get the three fields to show and your eventlistener works well. If you want to set a value for the fields, e.g. automatically set the value for email after login has been filled out, just use email.setValue(administrateur.getEmail().toString()); (for instance after an event such as buttonclick).

Have you had a look at Vaadin Forms? This could make creating and persisting forms such as this even easier. See for instance the 5minute demo at
https://vaadin.com/tutorial
and how ‘contactEditor’ is just given a datasource. More info
in the Book of Vaadin.

La question n’est pas très claire. Que voulez-vous faire au juste ? Je suggère vraiment de regarder les exemples du tutoriel et du livre.

(French is not the person’s native language either, so we’re left guessing)

thank you;
i followed this tutorial
https://vaadin.com/fr/tutorial

i tried to convert in vaadin hibernate spring postgressql project
i injected spring and hibernate succufely
but i am not reach to work this project

i did the contact entity and contactDao


package com.businessdecision.entity;

public class Contact{
	
	private String fname;
	private String lname;
	private String email;
        private String company;
	
	public Contact() {
		// TODO Auto-generated constructor stub
	}

	public String getfname() {
		return fname;
	}

	public void setfname(String fname) {
		this.fname= fname;
	}

	public String getlname() {
		return lname;
	}

	public void setlname(String lname) {
		this.lname= lname;
	}

	public String getEmail() {
		return email;
	}

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

	public void secompany(String company) {
		this.company= company;
	}

}

this ContactDao


package com.businessdecision.dao;

import static org.hibernate.criterion.Example.create;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.businessdecision.entity.Contact;



@Repository
public class ContactDAO {

	/**
	 * 
	 */
	@SuppressWarnings("unused")
	private static final Logger trace = Logger.getLogger(ContactDao.class);
	/**
	 * 
	 */
	private HibernateTemplate hibernateTemplate;

	/**
	 * 
	 * @param transientInstance
	 */
	public void persist(Contact transientInstance) {

		hibernateTemplate.save(transientInstance);

	}

	/**
	 * 
	 * @param instance
	 */
	public void saveOrUpdate(Contact instance) {

		hibernateTemplate.saveOrUpdate(instance);
		

	}

	public void save(Contact instance) {

		hibernateTemplate.save(instance);

	}

	public void update(Contact instance) {

		hibernateTemplate.update(instance);

	}

	public void delete(Contact persistentInstance) {

		hibernateTemplate.delete(persistentInstance);

	}

	public Contact merge(Contact  detachedInstance) {

		Contact  result = (Contact) hibernateTemplate
				.merge(detachedInstance);
		return result;

	}

	public Contact findById(String id) {

		try {
			Contact instance = (Contact) hibernateTemplate.get(
					"com.businessdecision.entity.Contact", id);

			return instance;
		} catch (RuntimeException re) {

		}
		return null;
	}

	

	@SuppressWarnings("unchecked")
	public List<Contact> findByExample(final Contact instance) {

		return (List<Contact>) this.hibernateTemplate
				.execute(new HibernateCallback() {

					@Override
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						try {
							List<Contact> results = session
									.createCriteria(
											"com.businessdecision.entity.Contact")
									.add(create(instance)).list();

							return results;
						} catch (RuntimeException re) {

						}
						return null;
					}
				});

	}

	public List<Contact> findAll() {

		return (List<Contact>) this.hibernateTemplate
				.execute(new HibernateCallback() {

					@Override
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						try {
							List<Contact> results = session
									.createCriteria(
											"com.businessdecision.entity.Contact")
									.list();

							return results;
						} catch (RuntimeException re) {

						}
						return null;
					}
				});

	}

	/**
	 * @return the hibernateTemplate
	 */
	public HibernateTemplate getHibernateTemplate() {
		return this.hibernateTemplate;
	}

	/**
	 * @param hibernateTemplate
	 *            the hibernateTemplate to set
	 */
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		if (hibernateTemplate == null)
			throw new NullPointerException("hibernateTemplate must not be null");

		this.hibernateTemplate = hibernateTemplate;
	}

}

In order to connect your user interface to your database, Vaadin uses something called a container. For Hibernate, there is the HbnContainer, for using JPA Criteria queries (similar to those in your example) there is the JPA Criteria LazyQueryContainer, and for standard SQL there is the SQLContainer. If your project meets the conditions you can also use Vaadin’s JPA Container (a licence is required if your code is not under an open-source licence).

There are sections on data bindings and on the JPA container in the book of Vaadin.

Hi Jean
have you an example can help me
because i not understand how i will begin
thank you

Hi Fredrik
could you send how to impliment my example (email.setValue(administrateur.getEmail().toString()):wink: