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.
| Online: | 7 Members of 4087 |
| Forum: Seam Users |
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.
If you run inside an appserver then injections via ejb-jar.xml should be used.
Thanks for the response. Can you give an example?
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
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.
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
Grrr-eat. That's good to hear. Thanks for the clarification Luke.