When the component is instantiated it will live in the event scope NOT the component will be instantiated whenever the event scope is accessed. There is no way (AFAIK) of doing this.
Beans are instantiated when they are accessed (via @In, @Out, accessed from a JSF page etc.)
This seems like a step backwards from JSP. Here's the problem I'm facing:
I have a signup form where users can select their country. There are about 200 countries, and a I have an enum that lists them all, and within that enum class there is also a static member which is a Map<String,String> that maps keys of country codes ("US") to values of country names ("United States"). Pretty basic stuff.
It seems like I should be able to use that Map as the value of a selectItems component.
But I cannot find any way to get that Java Map visible within the JSF!
I have a SFSB that also is the bean that processes the form. I put in a getCountryMap() method in that that always returns this map. But whenever I try to display the page, that doesn't work, because when the page is first displayed, that SFSB has not yet been instantiated, even though it has an EVENT scope.
So... this is ridiculous. There must be some way to display simple Java objects within JSF. Is there some way I could inject that Map into one of Seam's contexts?
Hard things, like redisplaying a form, are very easy in Seam, but simple things, like display some dumb Java objects, are difficult or impossible it appears.
I figured out a way to do it. I created a new class, called CountrySelect. I gave it a name, and an Application scope, and one method, which is getCountryMap. So that works now. I suppose if a class has APPLICATION scope, only one instance of it is created?
And again, I'm back to "error during model data update". I assume that that error is happening because the object is null. And yet the object has a CONVERSATION scope, so it seems to me that it should always exist as long as their is a conversation.
Is there some way to tell seam, "Please create this object and put it in the given context so I can process this page"?
It seems totally random to me how Seam decides which objects to create and when.
By the way, on my SFSB, I do have @In(creatte=true), and that doesn't seem to do any good.
Ah, I found out the problem.
In my entity class, I had a @Roles(...) annotation which gave role names and scopes. I thought that would be enough to use the object. No! A @Name annotation must be present, even if the given name is not used.
And now I have my CountrySelect class working, I figured out that instead of returning a Map, it needs to return a List of SelectItems. So I got that done. Then I found out that, because I'm using an enum for my Country, I need to write a Converter for that. Which turned out to be very easy to do, and within a few minutes I had my enum countries working, displaying a select list, etc. So a good select list on the HTML side, and correct Java style on the Java side (using an enum instead of a bunch of strings). And then I set the EnumType.STRING, so it saves it in the DB as a country code string. It's pretty amazing when all this stuff works.
STATELESS components are created every time they are used, not EVENT components :-)