-
1. Re: Facelets component and Seam
dan.j.allen Oct 4, 2008 3:30 AM (in response to bashan)No, Seam does not alter the way that JSF works fundamentally. What you are observing is typical behavior of the encoding/decoding process of the UI component tree. During that process, certain attributes are evaluated multiple times. The rendered attribute is the worst offender, often called more a half dozen times (and depending on how many times you reference it, that number could go up).
My advice to you is not to put logic in your
getter
methods, but rather treat them as a way to merely read the state of a component. If you do need to perform logic, I advise you to use a @Create or @Factory method, depending on what fits. -
2. Re: Facelets component and Seam
bashan Oct 4, 2008 3:09 PM (in response to bashan)sorry, I think I didn't explain myself very well. I know that jsf got a tendency of actvating methods several times. I wanted to know if seam has a good solution to method call with parameters, like in the example I gave.
thanks. -
3. Re: Facelets component and Seam
andygibson.contact.andygibson.net Oct 5, 2008 7:14 PM (in response to bashan)I think you still need to clarify further. Seam does deal with method call parameters like the example you gave, assuming of course that user is a valid variable and references the user entity.
Cheers,
Andy
-
4. Re: Facelets component and Seam
bashan Oct 7, 2008 5:14 PM (in response to bashan)I know Seam doesn't deal with method call parameters. This is a feature of facelets...
But, suppose I have a method with a parameter (most of the times it is one parameter, that is being passed to a Seam component...), and I want to make sure, this method will not be calculated half dozen times, like JSF tends to do, will @Factory pattern help me? -
5. Re: Facelets component and Seam
bashan Oct 7, 2008 7:15 PM (in response to bashan)Right now, in order to solve this. I am injecting to the service a variable. and I make sure to initialize it. This service is used with some of my facelets component. But, what would happen, if the XHTML code will be organize in a manner, the service factory method will be called before my Action component was created?
This is what I am doing:
@Name("userService") public class UserService { @In UserDAO userDAO; @In User serviceUser; @Factory(value="avatarMedium", scope=ScopeType.CONVERSATION) public String getAvatarMediumUrl() { return PathUtil.getAvatarMediumUrl(serviceUser.getUserId()); } @Factory(value="userVideos", scope=ScopeType.CONVERSATION) public List<Video> getUserVideos() { return userDAO.getVideos(serviceUser); } }
The serviceUser is the member I am injecting, I initialize it in an Action bean.
Is it a good way? is there a better solution?