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
12. Mar 2008, 20:23 CET | Link

Hi -- I have Seam components defined via the @Name annotation, but I want to externalize some configuration and pass in the values via components.xml,

i.e.


@Name("weatherBean")
public class WeatherBean { ...

}

And then in components.xml...


	<component name='weatherBean'>
		<property name="requestURL">@myPT.weather.requestURL@</property>
	</component>

I was hoping Seam would auto-create based on the Name annotation and then merge the configuration from components.xml given the matching name. However this doesn't seem to work. Do I have to choose either annotations or XML configuration?

Thanks.

6 Replies:
12. Mar 2008, 20:30 CET | Link
I want to externalize some configuration

If you run inside an appserver then injections via ejb-jar.xml should be used.

12. Mar 2008, 20:59 CET | Link

Thanks for the response. Can you give an example?

12. Mar 2008, 21:45 CET | Link
Tom Nichols wrote on Mar 12, 2008 08:23 PM:
I was hoping Seam would auto-create based on the Name annotation and then merge the configuration from components.xml given the matching name. However this doesn't seem to work. Do I have to choose either annotations or XML configuration?

Oh, heck no - what do you think this is, Hibernate? *ducks* >:-D

Seriously though, I've successfully followed section 4.2 of the manual before; so long as your component has a setter method for the property (in your case, setRequestURL(String url)), it should work precisely as you describe. It has to be a method, though (not just a field) - have you got one?

(OTOH, I'd like to know how Thomas's ejb-jar.xml idea would work too ...)

 

Luke Maurer

14. Mar 2008, 14:39 CET | Link
Luke Maurer wrote on Mar 12, 2008 09:45 PM:
Seriously though, I've successfully followed section 4.2 of the manual before; so long as your component has a setter method for the property (in your case, setRequestURL(String url)), it should work precisely as you describe. It has to be a method, though (not just a field) - have you got one?

Yes, weatherBean has a setRequestURL(String) method.

Ok, it seems like it is working now, I'm not sure why I wasn't seeing the desired behavior before... I went through section 4.2 several times and there are only a couple examples of a <component> definition without a class attribute. So it was a bit ambiguous. There's no real example of combining both annotations and XML definition.

Conversely, if I define a component in components.xml, can that class use annotations like @Logger?

Thanks.

18. Mar 2008, 02:56 CET | Link

AFAICT, there isn't a separate processing engine in Seam for annotations vs. XML (as there is in Hibernate, where annotations and XML don't (yet) play as nicely together). components.xml just augments the annotations and externalizes properties. So a component without a @Name should still have any annotations like @In, @Out, @Logger, @DataModel, etc. work just fine.

 

Luke Maurer

18. Mar 2008, 12:45 CET | Link

Grrr-eat. That's good to hear. Thanks for the clarification Luke.