-
1. Re: Can i use another kind of architeture for a SEAM applica
christian.bauer May 4, 2007 3:14 PM (in response to carlos.abreu)I don't understand what you want to do. Please post some pseudo code or something.
-
2. Re: Can i use another kind of architeture for a SEAM applica
carlos.abreu May 4, 2007 3:32 PM (in response to carlos.abreu)Hy Christian basically what i need is to pass forward objects from my Action Class, to a generic Action class..
Example:
public abstract class BaseAction(){
private BaseEntity em;
protected void setEntity(BaseEntity em){
this.em = em;
}
}
public class CompanyAction extends BaseAction{
@In
private Company company; // Entity Object, implements BaseEntity
public CompanyAction(){
super.setEntity(company);
}
}
However, i am not receiving the entity on the BaseAction, when i debug my code it comes a null object on the super class.
Thanks for the atention...
Carlos -
3. Re: Can i use another kind of architeture for a SEAM applica
delphi'sghost May 4, 2007 3:40 PM (in response to carlos.abreu)If I'm understanding correctly, you want to use a more "spring like" service/dao design for developing your application? .You can implement DAOs and have them injected into your stateful beans :
I think you can implement your DAOs as stateless session beans since the only 'state' you have is injected each time the bean is called :
(forgive the syntax errors)@Stateless @Name("personDAO") public class PersonDAOBean implements PersonDAO { @PersistenceContex private EntityManager em; public List<Person> findPeopleByFirstName(String firstName) { return em.createQuery("Select p from person where firstName = :firstName) .setParam("firstName",firstName) .getResultList(); }
In your action bean part, simply inject the DAO into it@Name("personSearch") @Stateful @Scope(CONVERSATION) public class PersonSearchBean implements PersonSearch { @In private PersonDAO personDAO; private List<Person> results; private String firstNameParam; public void doSearch() { results = personDAO.findPeopleByFirstName(firstNameParam); } ...
or something like that. -
4. Re: Can i use another kind of architeture for a SEAM applica
christian.bauer May 4, 2007 3:41 PM (in response to carlos.abreu)I don't think injection occurs during construction of the CompanyAction Seam component (it has a @Name, right?). You might want to use a lookup in the constructor with Component.getInstance("company") instead.
-
5. Re: Can i use another kind of architeture for a SEAM applica
delphi'sghost May 4, 2007 3:46 PM (in response to carlos.abreu)Oops, sorry, posted before I saw your last post describing your problem.
From your code, the injection happens after the constructor is called.
What you need is :@Create public void forwardToBaseAction() { super.setEntity(company) }
The @Create annotated method is called each time the bean is created and after injection has occurred. -
6. Re: Can i use another kind of architeture for a SEAM applica
carlos.abreu May 4, 2007 8:33 PM (in response to carlos.abreu)Delphi i understand your sugestion, but when should i call the forwardToBaseAction() ??? In my Action constructor ??
Thanks in advance for your time guys... -
7. Re: Can i use another kind of architeture for a SEAM applica
christian.bauer May 4, 2007 9:01 PM (in response to carlos.abreu)It's called by Seam when the component is instantiated, hence @Create. My solution is easier, call super(Component.getInstance("customer")) in your constructor.
-
8. Re: Can i use another kind of architeture for a SEAM applica
carlos.abreu May 4, 2007 9:25 PM (in response to carlos.abreu)Ow, it's quite obvious i didn't realize that... You sugested to do something like this :
public CompanyAction(){
super.setEntitty(Component.getInstance("company"));
}
The object attributes that will be passed to the super class will not be null ??
Thanks -
9. Re: Can i use another kind of architeture for a SEAM applica
delphi'sghost May 4, 2007 9:37 PM (in response to carlos.abreu)Hey Carlos
but when should i call the forwardToBaseAction() ??? In my Action constructor ??
As Christian said, the @Create annotation tells seam to call this function once the bean has been constructed.
If you use Christians method beware that when you call setEntity, you are still in the constructor, so therefore nothing has been injected yet. This could cause problems, i.e. if you have code in setEntity which writes to the @Logger, then the logger won't be injected yet.
You can get around it using the same syntax (something like Component.getInstance("org.jboss.seam.Logger")) but why use 2 methods of accessing components in your beans?
Personally, I always create a @Create annotated create method so I can write code in it that will be called only once all the items have been injected.
But hey, both will work. -
10. Re: Can i use another kind of architeture for a SEAM applica
carlos.abreu May 5, 2007 3:31 PM (in response to carlos.abreu)Thanks very much for the tips given, they will be very helpful. Last question....
There is a place to host a seam application ? I'm thinking in develop a project using SEAM and provide to the open community...
thanks -
11. Re: Can i use another kind of architeture for a SEAM applica
delphi'sghost May 5, 2007 6:22 PM (in response to carlos.abreu)I don't know anyplace that currently does it, but I'm no expert. Take a look at Michael Yuans posts about virtual private servers that lets you put what you want on the server.
I'll refer you to his blog for details :
http://www.michaelyuan.com/blog/index.php?s=hosting -
12. Re: Can i use another kind of architeture for a SEAM applica
carlos.abreu May 7, 2007 10:13 AM (in response to carlos.abreu)Hy Delphi and Christian, thanks for the tips... It worked very well in my application