views:

290

answers:

4

I have a very simple piece of code that reads like:

@In(create = true) OutletHome outletHome;

It was working fine (using Seam 2.2.0.GA), and the object was being created and injected without any problems. But when I tried changing it to:

@In(create = true) OutletHome deactivationOutletHome;

It suddenly stopped working, causing the exception:

org.jboss.seam.RequiredException: @In attribute requires non-null value: customerHome.deactivationOutletHome

What could be the cause for such a problem? How is the variable name relevant? And how could I fix it?

+1  A: 

This is a guess but:

If you have to make sure the variable name is the same as the one you declared in your components.xml file.

Maybe try:

@In(create = true, value="#{outletHome}")
OutletHome deactivationOutletHome;
Peter D
Thank you. This is correct and solves my problem, but @cetnar's answer is clearer and more precise.
Hosam Aly
+1  A: 

From the Seam documentation (emphasis added):

By default, Seam will do a priority search of all contexts, using the name of the property or instance variable that is being injected. You may wish to specify the context variable name explicitly, using, for example, @In("currentUser").

I would guess you have a OutletHomeImpl that looks something like:

@Name("outletHome")
class OutlookHomeImpl implements OutletHome { ... }

For Seam to do the injection, the variable needs to have the same name as the bean you want to inject. There are alternative ways of doing this, but this is the "convention over configuration" way.

David Krisch
Thank you. This is partially correct, as I don't have an `Impl` class, but the note on the variable name pins down the cause of my problem.
Hosam Aly
+2  A: 

Try,


@In(create = true, value="outletHome")
OutletHome deactivationOutletHome;

Value you inject must be a seam component. When attribute "value" is missed is assumed that is equal to field name that into is injected.

Others ways to access seam components are:


@In(value="componentName", create = true)
@In("#{componentName}")
cetnar
Thank you. This is a precise description of my problem. The matching is being done by the variable name, whereas I used to think that it was being done by the class name.
Hosam Aly
+1  A: 

Remember that SEAM works with a configuration by exception "paradigm". In this case the exception is that the variable name is not equal to the name of the component, so you are forced to explicitly tell seam which component you are searching for.

This is good because it can lead to write less code, if you follow the standard, but it can lead to some doubts like this one if you don't remember about what's happening behind the scenes :)

tiago