Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
19. Feb 2008, 12:09 CET | Link

I want to inject some components for data access etc into my validators. Is it possible to use a hibernate validator class as a seam component? If not, is it possible to reach an instance of a seam component from the validator?

9 Replies:
19. Feb 2008, 13:07 CET | Link

So far I've done this in components.xml

	<component name="myDao"
		class="MyDao"
		auto-create="true" scope="stateless" />

	<component name="myValidator"
		class="MyValidator"
		auto-create="true" scope="stateless">
		<property name="myDao">#{myDao}</property>
	</component>

myValidator is an instance of org.hibernate.Validator.Validator. myDao is a static property of myValidator, and I attempt to inject it via EL in components.xml.

This doesn't work. When I reach the isValid-method of myValidator, myDao has value null.

Does anyone have a better example of using seam-components from hibernate validator instances?

19. Feb 2008, 13:15 CET | Link

By the way, I cannot use seam annotations in myDao and myValidator since they are shared by a non-seam project.

19. Feb 2008, 14:38 CET | Link

You could call Component.getInstance() from inside the validator class, I suppose...

 

Learn more about Web Beans...

20. Feb 2008, 08:47 CET | Link

I tried this (in the validators initialize()-method):

this.myDao = (MyDao) Component.getInstance(MyDao.class);

and got

No @Name annotation for class: MyDao

As listed previously, I already configured MyDao in components.xml - so it has no @Name annotation. Is this a bug? Is there another way to get hold of seam components from non-seam components?

20. Feb 2008, 09:58 CET | Link
Eirik Larsen wrote on Feb 20, 2008 08:47 AM:
Is there another way to get hold of seam components from non-seam components?

How does Contexts.lookupInStatefulContextorsomethinglikethat react?

 

If a man speaks in the forest and there is no woman around to hear him, is he still wrong?

20. Feb 2008, 11:17 CET | Link

Use Component.getInstance("myDao");

 

Read about how to report a bug.

20. Feb 2008, 11:17 CET | Link
How does Contexts.lookupInStatefulContextorsomethinglikethat react?

It works IF I already have myDao in a stateful scope. However, this is not so easy to accomplish in components.xml (I cannot annotate as MyDao is shared between projects).

I've created a temporary component that starts up myDao:

@Scope(APPLICATION)
@Name("daoHelper")
@Startup(depends = "myDao")
public class ValidatorHelper {}

I really hope to get rid of this one and do something similar to the @Startup-annotation in my components.xml instead. Ideas?

20. Feb 2008, 11:30 CET | Link
Use Component.getInstance("myDao")

Thanks Pete, that worked without daoHelper to initialize myDao.

30. Jun 2008, 16:59 CET | Link

Is there an easier way to do this if annotations are an option? Also, what are the repercussions of using Component.getInstance()? That is the method I am currently trying, but it is somehow causing an infinite loop leading to a StackOverflowException when I call flush(). Any help is appreciated.