Vaadin with Seam

Hello everybody,

First at all; I would like to congratulate all the team for their great job on Vaadin. I’am really impressed.

The thing is that I have to use Seam/JSF and Vaadin in the same application.

I have a already big application working with MySQL/Hibernates/Seam/JSF-RichFaces.
I would like to propose to my client a more user-friendly interface and with modern browser I think that RIA have good futur. For that, I want to use Vaadin.

I made a few design study. I want to keep the database / hibernates entities.
I will redo a new business layer (for complex treatment) working for Seam/JSF backbean

My problems are :

  • How to manage with Hibernate Session. What the best way ? Invoking a seam component and get entityManager by injection or going with classic hibernate session ?
  • What about Lazy loading ?
  • How to link authentication with Seam JAAS

Does anyone have already done this ?
Any advice ?

Regards,
Fred

Hi !
We have seam (jpa + richfaces) application and we want to redesign some forms using vaadin to make them more usable.
So i started to try to use seam contexts and components with vaadin application.
Here is my experience (experimental):
Vaadin and seam works fine together (for seam vaadin is just another user’s servlet)
but:

  1. add vaadin servlet path (used in web.xml) to seam filter mapping

  2. we need to manage transactions:
    // in Application init code
    getContext().addTransactionListener(new SeamTransactionListener());
    and SeamTransactionListener is (based on seam code):

public class SeamTransactionListener implements TransactionListener {

	private static final long serialVersionUID = 1L;

	public void transactionEnd(Application application, Object transactionData) {
		// will unlock the conversation if any locked
		Manager.instance().unlockConversation();
		System.out.println("Transaction end");

		if (Init.instance().isTransactionManagementEnabled())
			commitOrRollback(); // we commit before destroying contexts, cos the
	}

	public void transactionStart(Application application, Object transactionData) {
		// TODO Auto-generated method stub
		System.out.println("Transaction start");
		if (Init.instance().isTransactionManagementEnabled())
			begin();
		if (application instanceof VApp) 
			((VApp) application).nextTransaction();
	}

	private void commitOrRollback() {
		try {
			if (Transaction.instance().isActive()) {
				try {
					Transaction.instance().commit();
				} catch (IllegalStateException e) {
					System.err
							.println("TX commit failed with illegal state exception. This may be "
									+ "because the tx timed out and was rolled back in the background.");
				}
			} else if (Transaction.instance().isRolledBackOrMarkedRollback()) {
				Transaction.instance().rollback();
			}

		} catch (Exception e) {
			throw new IllegalStateException("Could not commit transaction", e);
		}
	}

	private void begin() {
		try {
			if (!Transaction.instance().isActiveOrMarkedRollback()) {
				// log.debug("beginning transaction ");
				Transaction.instance().begin();
			}
		} catch (Exception e) {
			throw new IllegalStateException("Could not start transaction", e);
		}
	}

}

We use seam’s conversations, so when i need to use some conversation-scope components from vaadin event listeners, i call this method to “attach” to some conversation:

public static void restoreConversation(String cid) {
			System.out.println("Restoring conversation " + cid);
			System.out.println("Existsing conversations : "
					+ ConversationEntries.instance().getConversationIds());
			
			if (Conversation.instance().isLongRunning() ) {
				if (Conversation.instance().getId().equals(cid)) {
					System.out.println("already here : " + cid);
					return;
				} else 
					Manager.instance().unlockConversation();
			}
			

			Map<String, Object> params = new HashMap<String, Object>();
			params.put(Manager.instance().getConversationIdParameter(), cid);
			ConversationPropagation.instance().restoreConversationId(params);
			Manager.instance().restoreConversation();
}

So all seam features (entityManager, identity, etc) works fine.
For example, user can login using vaadin form -

...
        private TextField userName;
	private TextField pwd;
.....
 Button b = new Button("Login");
        b.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				login();
			}
		});
....

protected void login() {
		Identity identity = Identity.instance();
		identity.setUsername(userName.getValue().toString());
		identity.setPassword(pwd.getValue().toString());
		
		identity.login();
		
		if (identity.isLoggedIn()) {
			getWindow().showNotification("Welcome, " + identity.getCredentials().getUsername());
			// do some user-specific sfuff here (load menu, show main form, etc)
		} else {
			getWindow().showNotification("Oops !",  Notification.TYPE_ERROR_MESSAGE);
		}
		
	}
...

Hi Maxim !

I’m triying to do the same thing with your code: integrate vaadin to a seam application but it’s not working for me…

Could you please provide some more details ?

Your web.xml file content for example or any other helping source…

Thanks

Salvo

This solution is also valid with SEAM 3.0.0 ???

Thank you

Please everybody…I really need your help !!! :frowning: