<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Dan,<div><br></div><div>I really like the both approaches and I think method is appropriate for the specific use case the only thing is if all that runtime selection stuff happen per request, wouldn't that be a performance killer? I know the those call times are minuscule, but if that would become a pattern for the rest of the framework, those numbers could really add up. </div><div><br></div><div>Now why would someone really mix Wicket and JSF together in a single app? In addition, if you do want to allow that runtime selection and allow users to mix and match different view frameworks at runtime, then you need to think about a page that has both JSF and Wicket elements on it, for example a portal style app. Then you really need to think about who consumes what/when.</div><div><br></div><div>cheers,</div><div><br></div><div><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">Drew Kutcharian</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">Chief Technology Officer</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">Venarc Inc. <a href="http://www.venarc.com">www.venarc.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">Phone: 818-524-2500</div><div><br></div></div></div></div></div></div></div><div><div><div>On May 26, 2009, at 9:59 PM, Dan Allen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Regarding the discussion of the design for StatusMessages...<br><br><div class="gmail_quote">On Tue, May 5, 2009 at 7:59 AM, Clint Popetz <span dir="ltr"><<a href="mailto:cpopetz@gmail.com">cpopetz@gmail.com</a>></span> wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I want to<br> point out that using a deployment type and @Specializes would seem to<br> place us in the same situation as Seam 2.x with respect to the view<br> layers co-existing in the same deployment, which<br> <a href="https://jira.jboss.org/jira/browse/JBSEAM-3645" target="_blank">https://jira.jboss.org/jira/browse/JBSEAM-3645</a> was meant to address.<br> <br> In other words, I'd rather that the choice of the StatusMessages bean<br> that will be activated isn't based on deployment type, but rather is<br> chosen at runtime based on the type of request, using the pattern in<br> the patch for the above jira issue. Deployment types would of course<br> still be used to choose which implementations of things like<br> StatusMessages are available.</blockquote><div><br>I have taken a first stab at solving this problem. I'm open to other approaches, but first let me explain what I've done. As Clint points out, from one request to the next, you may be dealing with different frameworks (Wicket vs JSF for instance). But within the request, you want to be able to take specific actions relating to the current framework. Clearly, this is not the appropriate scenario for a deployment type since that is design for a setting/environment that is fixed. So I did some brainstorming.<br> <br>What I realized is that StatusMessages are really a generic repository that should be updated and consumed by the framework-specific activity. Therefore, it seems to me like there should be one and only one conversation-scoped StatusMessages. Then, if you want to have some extra methods for convenience (for instance in JSF to add a StatusMessage from an existing FacesMessage) you create a class which extends and wraps the StatusMessages component (StatusMessages would be injected into it and all overrides delegating to it). You could also override the onBeforeRender() method where you might put the logic for converting and transfering to the native message type and storage. The executor of that conversion would be implemented in the framework-specific listener.<br> <br>For instance, 9 out of 10 times you simply inject the StatusMessages to use in your application:<br><br>@Current StatusMessages statusMessages;<br><br>For JSF, there is a FacesMessages bean which inherits from StatusMessages (to keep the API the same) and delegates calls to the StatusMessages instance. It also adds the logic to create FacesMessage objects in the onBeforeRender() method<br> <br>public void onBeforeRender() {<br> super.onBeforeRender();<br> // create FacesMessage objects and register them here<br>}<br></div></div><br>The ConvertStatusMessagesListener (a JSF system event listener) executes the onBeforeRender() call.<br> <br>manager.getInstanceByType(StatusMessages.class, new AnnotationLiteral<Faces>() {}).onBeforeRender();<br><br>There are also some convenience methods on the FacesMessages instance. If you want to use them, you inject as follows:<br> <br>@Faces FacesMessages facesMessages;<br><br>I can't use @Current here because otherwise the resolution would be ambigous. I could just clone the StatusMessages API in the FacesMessages class to avoid having to use this binding type, so if you have a feeling/advice there, I would be glad to here it.<br> <br>Okay, that's one approach. Now for something different. There is a similar specialization w/ the Expressions class (an EL convenience API). If working within the JSF request, we want to override some methods so that the bean uses the current JSF EL context. In this case, I decided to try Clint's approach described in the cited issue report. A producer method will locate beans that have the binding type @RuntimeSelected and will consult the isActive() method to determine which one is prepared to handle the current request. The isActive() method comes from the RuntimeSelectedBean interface. So the bean must have both the binding type and the interface. There is a second binding type, @Default, which indicates which implementation should be used when there are no @RuntimeSelected implementations present or active. It is mutually exclusive with @RuntimeSelected.<br> <br>So you have:<br>public @Default class Expressions { ... }<br>public @RuntimeSelected class FacesExpressions extends Expressions, RuntimeSelectedBean {<br> public boolean isActive()<br> {<br> return FacesContext.getCurrentInstance() != null;<br> }<br>}<br><br>public @RuntimeSelected class WicketExpressions extends Expressions, RuntimeSelectedBean {<br> public boolean isActive()<br> {<br> return Application.exists();<br> }<br>}<br><br>The producer type for the Expressions bean is application-scoped and the producer method is dependent-scoped (or request-scoped?). The available instances are looked up when the producer is initialized and the instance is selected from this set each time the producer is resolved.<br> <br>Of course, I could have used this strategy for the StatusMessages too, except in the case of StatusMessages it is logical to use the shared/generic StatusMessages bean. It's only when you need to convert the messages do you need the specialization and therefore I think we can avoid having to do the runtime selection.<br> <br>I've committed all of this to the Seam trunk if you want to check it out. I'm open to suggestions...I'm just trying to get used WB and find a workable approach. The solutions we decide on are important because the define a standard practice we will follow as more cases arise.<br> <br>-Dan<br clear="all"><br>-- <br>Dan Allen<br>Senior Software Engineer, Red Hat | Author of Seam in Action<br><br><a href="http://mojavelinux.com">http://mojavelinux.com</a><br><a href="http://mojavelinux.com/seaminaction">http://mojavelinux.com/seaminaction</a><br> <a href="http://in.relation.to/Bloggers/Dan">http://in.relation.to/Bloggers/Dan</a><br><br>NOTE: While I make a strong effort to keep up with my email on a daily<br>basis, personal or other work matters can sometimes keep me away<br> from my email. If you contact me, but don't hear back for more than a week,<br>it is very likely that I am excessively backlogged or the message was<br>caught in the spam filters. Please don't hesitate to resend a message if<br> you feel that it did not reach my attention.<br> _______________________________________________<br>seam-dev mailing list<br><a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/seam-dev<br></blockquote></div><br></div><br></body></html>