[webbeans-dev] contextual action methods
by Dan Allen
On one of my first reads of the Web Beans spec, I had this vision of being
able to bind a method with arguments to a UI interface component and then
have Web Beans inject the parameters at invocation time. This would give
dependency injection that is isolated to the method call (and contextual).
<h:commandButton action="#{hotelSearch.find}" value="Search"/>
public void find(@Current SearchCriteria searchCriteria) {
...
}
However, once again we get stumped by the EL. The EL is going to look for a
method with no arguments or, as of EL 1.2, an argument count matching the
parameterized EL expression. What I would like is for the EL to locate a
method with the same name with 0 or more arguments where every argument can
be satisfied by Web Beans. Naturally, overloading would not be allowed since
it would introduce ambiguity. So you could have exactly one method like this
to be used as an alternative to a no-args method (the restriction would be
per method name of course).
The downside of doing #{hotelSearch.find(searchCriteria)} is that you have
to name (i.e., @Named) all possible arguments and you can't leverage binding
annotations (everything is name based).
We could do something like this in Seam 3, taking over the torch from Seam 2
that made Faces event arguments optional.
Thoughts?
-Dan
--
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://in.relation.to/Bloggers/Dan
NOTE: While I make a strong effort to keep up with my email on a daily
basis, personal or other work matters can sometimes keep me away
from my email. If you contact me, but don't hear back for more than a week,
it is very likely that I am excessively backlogged or the message was
caught in the spam filters. Please don't hesitate to resend a message if
you feel that it did not reach my attention.
15 years, 7 months
[webbeans-dev] JSR299 TCK beta1
by Pete Muir
All,
I'm pleased to say we have reached the first milestone in the JSR299
TCK. You can download the distro here: http://repository.jboss.org/maven2/org/jboss/jsr299/tck/parent/1.0.0.BETA...
Some stats:
* we have identified all assertions from Chapters 1, 2, 3, 4, 5, 6, 7,
8 leaving chapters 8, 11, and Appendix A (Chapter 10, Appendix B and
Appendix C contain signature info only).
* so far we have identified 1070 assertions, of which 459 are tested
using 402 tests. This is 43% of assertions.
* Of the 402 tests, 381 can be run standalone, and 21 require a full
EE environment. All can be run in an EE environment.
We are currently using these frameworks to aid testing:
* TestNG
* HtmlUnit
* Apache HttpClient
--
Pete Muir
http://www.seamframework.org
http://in.relation.to/Bloggers/Pete
15 years, 7 months
[webbeans-dev] binding Manager to JNDI on Jetty
by Dan Allen
In the process of setting up the servlet-booking example for Seam, I tackled
the problem of binding the JCDI Manager to JNDI on Jetty. It's just a matter
of extending the javax.naming.Reference class. I attached the implementation
to https://jira.jboss.org/jira/browse/WBX-31.
Should I commit this Pete? I need a decison on whether we should change the
name of the class to reflect that it is an ObjectFactory and a Reference. I
think internally Tomcat must create the reference automatically from the
resource definition, which is why Jetty doesn't know what to do with a plain
ObjectFactory.
...I also noticed that injection is not supported in Jetty. I'm not sure how
to handle that problem, but it means no booking yet on Jetty.
-Dan
--
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://in.relation.to/Bloggers/Dan
NOTE: While I make a strong effort to keep up with my email on a daily
basis, personal or other work matters can sometimes keep me away
from my email. If you contact me, but don't hear back for more than a week,
it is very likely that I am excessively backlogged or the message was
caught in the spam filters. Please don't hesitate to resend a message if
you feel that it did not reach my attention.
15 years, 7 months
[webbeans-dev] where outjection paid its dues
by Dan Allen
I quickly discovered how I've taken outjection for granted when I got
started with the booking example. I instinctively created a @Producer
methods to expose the hotels to the UI
<h:dataTable value="#{hotels}" var="_hotel">...</h:dataTable.
public
@Produces
@Named
@RequestScoped
List<Hotel> getHotels()
{
return hotels;
}
However, the problem is that before the find() action gets a chance to
invoke in response to the user clicking the Search button, JSF has already
called on the "hotels" context variable and it is assigned to the request
scope. So the UI doesn't see the updated value of the hotels property in the
Render Response phase. If this method is on a session-scoped bean, you can
perform a redirect after post and then the UI will get the right value.
What's the cleanest way to clear the context varaible in the find() method
so that the producer runs again in the Render Response phase?
-Dan
--
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://in.relation.to/Bloggers/Dan
NOTE: While I make a strong effort to keep up with my email on a daily
basis, personal or other work matters can sometimes keep me away
from my email. If you contact me, but don't hear back for more than a week,
it is very likely that I am excessively backlogged or the message was
caught in the spam filters. Please don't hesitate to resend a message if
you feel that it did not reach my attention.
15 years, 7 months
[webbeans-dev] Re: [webbeans-commits] Webbeans SVN: r2425 - in extensions/trunk: wicket and 7 other directories.
by Pete Muir
Hi Clint,
Thanks for this! My only comment is that we should really do this as a
library that works for any 299 impl, and isn't tied to Web Beans. This
is quite easy to achieve:
(1) remove the dependence on webbeans-core
(2) extract the non-contextual injection code into a jsr299-utils
library and have both the RI and Wicket integration depend on it -
this code should basically offer a service to allow injection of non-
contextual instances using only 299 apis.
Let me know if you want me to work on (2)...
On 16 Apr 2009, at 03:14, webbeans-commits(a)lists.jboss.org wrote:
> Author: cpopetz
> Date: 2009-04-15 22:14:25 -0400 (Wed, 15 Apr 2009)
> New Revision: 2425
>
> Added:
> extensions/trunk/wicket/
> extensions/trunk/wicket/pom.xml
> extensions/trunk/wicket/src/
> extensions/trunk/wicket/src/main/
> extensions/trunk/wicket/src/main/java/
> extensions/trunk/wicket/src/main/java/org/
> extensions/trunk/wicket/src/main/java/org/jboss/
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansApplication.java
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansComponentInstantiationListener.java
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansMetaData.java
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansRequestCycle.java
> extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansWebRequestCycleProcessor.java
> Log:
> Initial commit of wicket integration.
>
>
> Added: extensions/trunk/wicket/pom.xml
> ===================================================================
> --- extensions/trunk/wicket/pom.xml (rev 0)
> +++ extensions/trunk/wicket/pom.xml 2009-04-16 02:14:25 UTC (rev 2425)
> @@ -0,0 +1,56 @@
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
> " xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
> ">
> + <parent>
> + <artifactId>webbeans-parent</artifactId>
> + <groupId>org.jboss.webbeans</groupId>
> + <version>1.0.0-SNAPSHOT</version>
> + </parent>
> + <modelVersion>4.0.0</modelVersion>
> + <groupId>org.jboss.webbeans</groupId>
> + <artifactId>webbeans-wicket</artifactId>
> + <version>1.0.0-SNAPSHOT</version>
> + <name>Web Beans Wicket Integration</name>
> + <dependencies>
> +
> + <dependency>
> + <groupId>org.testng</groupId>
> + <artifactId>testng</artifactId>
> + <scope>test</scope>
> + <classifier>jdk15</classifier>
> + <exclusions>
> + <exclusion>
> + <artifactId>junit</artifactId>
> + <groupId>junit</groupId>
> + </exclusion>
> + </exclusions>
> + </dependency>
> + <dependency>
> + <groupId>org.jboss.webbeans</groupId>
> + <artifactId>jsr299-api</artifactId>
> + </dependency>
> + <dependency>
> + <groupId>org.jboss.webbeans</groupId>
> + <artifactId>webbeans-core</artifactId>
> + <scope>provided</scope>
> + </dependency>
> + <dependency>
> + <groupId>org.apache.wicket</groupId>
> + <artifactId>wicket</artifactId>
> + <version>${wicket.version}</version>
> + </dependency>
> + <dependency>
> + <groupId>javax.servlet</groupId>
> + <artifactId>servlet-api</artifactId>
> + <scope>provided</scope>
> + </dependency>
> +
> + </dependencies>
> +
> + <build>
> + <defaultGoal>install</defaultGoal>
> + </build>
> +
> + <properties>
> + <wicket.version>1.3-SNAPSHOT</wicket.version>
> + </properties>
> +
> +</project>
>
> Added: extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> wicket/WebBeansApplication.java
> ===================================================================
> --- extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansApplication.java (rev 0)
> +++ extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansApplication.java 2009-04-16 02:14:25 UTC (rev 2425)
> @@ -0,0 +1,54 @@
> +package org.jboss.webbeans.wicket;
> +
> +
> +import org.apache.wicket.Request;
> +import org.apache.wicket.RequestCycle;
> +import org.apache.wicket.Response;
> +import org.apache.wicket.protocol.http.WebApplication;
> +import org.apache.wicket.protocol.http.WebRequest;
> +import org.apache.wicket.protocol.http.WebResponse;
> +import org.apache.wicket.request.IRequestCycleProcessor;
> +
> +/**
> + * A convenience subclass of wicket's WebApplication which adds the
> hooks necessary to use JSR-299 injections
> + * in wicket components, as well as manage JSR-299 conversation
> scopes with Wicket page metadata. If you have
> + * your own WebApplication subclass, and can't subclass this class,
> you just need to do the three things that this
> + * class does, i.e. register the
> WebBeansComponentInstantiationListener, and override the two methods
> below to return
> + * the RequestCycle and IRequestCycleProcessor subclasses specific
> to WebBeans, or your subclasses of those classes.
> + * @author cpopetz
> + *
> + * @see WebApplication
> + * @see WebBeansWebRequestCycleProcessor
> + * @see WebBeansRequestCycle
> + */
> +public abstract class WebBeansApplication extends WebApplication
> +{
> + /**
> + * Use the constructor to add our component instantiation listener
> + * @see WebBeansComponentInstantiationListener
> + */
> + public WebBeansApplication()
> + {
> + addComponentInstantiationListener(new
> WebBeansComponentInstantiationListener());
> + }
> +
> + /**
> + * Override to return our WebBeans-specific request cycle
> processor
> + * @see WebBeansWebRequestCycleProcessor
> + */
> + @Override
> + protected IRequestCycleProcessor newRequestCycleProcessor()
> + {
> + return new WebBeansWebRequestCycleProcessor();
> + }
> +
> + /**
> + * Override to return our WebBeans-specific request cycle
> + * @see WebBeansRequestCycle
> + */
> + @Override
> + public RequestCycle newRequestCycle(final Request request, final
> Response response)
> + {
> + return new WebBeansRequestCycle(this, (WebRequest) request,
> (WebResponse) response);
> + }
> +}
>
>
> Property changes on: extensions/trunk/wicket/src/main/java/org/jboss/
> webbeans/wicket/WebBeansApplication.java
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> Added: extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> wicket/WebBeansComponentInstantiationListener.java
> ===================================================================
> --- extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansComponentInstantiationListener.java
> (rev 0)
> +++ extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansComponentInstantiationListener.java 2009-04-16 02:14:25 UTC
> (rev 2425)
> @@ -0,0 +1,20 @@
> +package org.jboss.webbeans.wicket;
> +
> +import org.apache.wicket.Component;
> +import org.apache.wicket.application.IComponentInstantiationListener;
> +import org.jboss.webbeans.CurrentManager;
> +import org.jboss.webbeans.manager.api.WebBeansManager;
> +
> +/**
> + * This listener uses the WebBeansManager to handle injections for
> all wicket components.
> + * @author cpopetz
> + * @see WebBeansManager
> + *
> + */
> +public class WebBeansComponentInstantiationListener implements
> IComponentInstantiationListener
> +{
> + public void onInstantiation(Component component)
> + {
> + ((WebBeansManager)
> CurrentManager.rootManager()).injectNonContextualInstance(component);
> + }
> +}
> \ No newline at end of file
>
>
> Property changes on: extensions/trunk/wicket/src/main/java/org/jboss/
> webbeans/wicket/WebBeansComponentInstantiationListener.java
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> Added: extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> wicket/WebBeansMetaData.java
> ===================================================================
> --- extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansMetaData.java (rev 0)
> +++ extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansMetaData.java 2009-04-16 02:14:25 UTC (rev 2425)
> @@ -0,0 +1,21 @@
> +package org.jboss.webbeans.wicket;
> +
> +import org.apache.wicket.MetaDataKey;
> +
> +/**
> + * Public storage for the metadata key used by the WebBeans
> integration to store
> + * conversation ids in wicket page metadata.
> + * @author cpopetz
> + *
> + */
> +public class WebBeansMetaData
> +{
> +
> + /**
> + * This is the key we will use to to store the conversation
> metadata in the
> + * wicket page.
> + */
> + public static final MetaDataKey CID = new
> MetaDataKey(String.class) {
> + private static final long serialVersionUID =
> -8788010688731927318L;
> + };
> +}
>
>
> Property changes on: extensions/trunk/wicket/src/main/java/org/jboss/
> webbeans/wicket/WebBeansMetaData.java
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> Added: extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> wicket/WebBeansRequestCycle.java
> ===================================================================
> --- extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansRequestCycle.java (rev 0)
> +++ extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansRequestCycle.java 2009-04-16 02:14:25 UTC (rev 2425)
> @@ -0,0 +1,108 @@
> +package org.jboss.webbeans.wicket;
> +
> +import javax.context.Conversation;
> +import javax.inject.manager.Manager;
> +
> +import org.apache.wicket.IRequestTarget;
> +import org.apache.wicket.Page;
> +import org.apache.wicket.Response;
> +import org.apache.wicket.protocol.http.WebApplication;
> +import org.apache.wicket.protocol.http.WebRequest;
> +import org.apache.wicket.protocol.http.WebRequestCycle;
> +import
> org
> .apache.wicket.request.target.component.BookmarkablePageRequestTarget;
> +import org.apache.wicket.request.target.component.IPageRequestTarget;
> +import org.jboss.webbeans.CurrentManager;
> +import org.jboss.webbeans.context.ConversationContext;
> +import org.jboss.webbeans.conversation.ConversationManager;
> +import org.jboss.webbeans.servlet.ConversationBeanStore;
> +
> +/**
> + * WebBeansRequestCycle is a subclass of the standard wicket
> WebRequestCycle which:
> + * <ul>
> + * <li>restores long-running conversations specified in wicket page
> metadata when a page target is first used.
> + * <li>propagates long running conversations to new page targets by
> specifying the above metadata
> + * <li>propagates long running conversations across redirects
> through the use of a request parameter if the
> + * redirect is handled with a BookmarkablePageRequest
> + * <li> Sets up the conversational context
> + * </ul>
> + * @see WebBeansWebRequestCycleProcessor Which handles propogation
> of conversation data for newly-started
> + * long running conversations, by storing their ids in the page
> metadata
> + * @author cpopetz
> + *
> + */
> +public class WebBeansRequestCycle extends WebRequestCycle
> +{
> + public WebBeansRequestCycle(WebApplication application,
> WebRequest request, Response response)
> + {
> + super(application, request, response);
> + }
> +
> + /**
> + * Override to set up the conversation context and to choose the
> conversation if a conversation id
> + * is present in target metadata.
> + */
> + @Override
> + protected void onRequestTargetSet(IRequestTarget target)
> + {
> + super.onRequestTargetSet(target);
> +
> + Page page = null;
> + if (target instanceof IPageRequestTarget)
> + {
> + page = ((IPageRequestTarget) target).getPage();
> + }
> +
> + //Two possible specifications of cid: page metadata or
> request url; the latter is used
> + //to propagate the conversation to mounted (bookmarkable)
> paths after a redirect
> +
> + String specifiedCid = null;
> + if (page != null)
> + {
> + specifiedCid = (String)
> page.getMetaData(WebBeansMetaData.CID);
> + }
> + else
> + {
> + specifiedCid = request.getParameter("cid");
> + }
> +
> + Manager manager = CurrentManager.rootManager();
> + Conversation conversation =
> manager.getInstanceByType(Conversation.class);
> +
> + //restore a conversation if it exists
> + if (specifiedCid != null)
> + {
> + // Restore this conversation
> +
> manager
> .getInstanceByType
> (ConversationManager.class).beginOrRestoreConversation(specifiedCid);
> + }
> +
> + //handle propagation of existing long running converstaions
> to new targets
> + if (conversation.isLongRunning())
> + {
> + //Note that we can't propagate conversations with other
> redirect targets like
> + //RequestRedirectTarget through this mechanism, because it
> does not provide an
> + //interface to modify its target URL. If propagation with
> those targets is to be supported,
> + //it needs a custom Response subclass.
> + if (isRedirect() && target instanceof
> BookmarkablePageRequestTarget)
> + {
> + BookmarkablePageRequestTarget bookmark =
> (BookmarkablePageRequestTarget) target;
> + //if a cid has already been specified, don't override it
> + if (!bookmark.getPageParameters().containsKey("cid"))
> + bookmark.getPageParameters().add("cid",
> conversation.getId());
> + }
> +
> + //If we have a target page, propagate the conversation to
> the page's metadata
> + if (page != null)
> + {
> + page.setMetaData(WebBeansMetaData.CID,
> conversation.getId());
> + }
> + }
> +
> + //Now set up the conversational context if it isn't already
> + if (!ConversationContext.INSTANCE.isActive())
> + {
> + ConversationContext.INSTANCE.setBeanStore(
> + new
> ConversationBeanStore
> (((WebRequest)request).getHttpServletRequest().getSession(),
> conversation.getId()));
> + ConversationContext.INSTANCE.setActive(true);
> + }
> + }
> +}
> \ No newline at end of file
>
>
> Property changes on: extensions/trunk/wicket/src/main/java/org/jboss/
> webbeans/wicket/WebBeansRequestCycle.java
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> Added: extensions/trunk/wicket/src/main/java/org/jboss/webbeans/
> wicket/WebBeansWebRequestCycleProcessor.java
> ===================================================================
> --- extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansWebRequestCycleProcessor.java (rev 0)
> +++ extensions/trunk/wicket/src/main/java/org/jboss/webbeans/wicket/
> WebBeansWebRequestCycleProcessor.java 2009-04-16 02:14:25 UTC (rev
> 2425)
> @@ -0,0 +1,44 @@
> +package org.jboss.webbeans.wicket;
> +
> +import javax.context.Conversation;
> +
> +import org.apache.wicket.Page;
> +import org.apache.wicket.RequestCycle;
> +import org.apache.wicket.protocol.http.WebRequestCycleProcessor;
> +import org.jboss.webbeans.CurrentManager;
> +import org.jboss.webbeans.context.ConversationContext;
> +import org.jboss.webbeans.conversation.ConversationManager;
> +
> +/**
> + * WebBeansWebRequestCycleProcessor is a subclass of the standard
> wicket WebRequestCycleProcessor which saves the conversation id
> + * of any long-running cornversation in wicket page metadata. It
> also cleans up the conversation context.
> + *
> + * @author cpopetz
> + *
> + */
> +
> +public class WebBeansWebRequestCycleProcessor extends
> WebRequestCycleProcessor
> +{
> + /**
> + * If a long running conversation has been started, store its id
> into page metadata
> + */
> + @Override
> + public void respond(RequestCycle requestCycle)
> + {
> + super.respond(requestCycle);
> + Conversation conversation =
> CurrentManager.rootManager().getInstanceByType(Conversation.class);
> + if (conversation.isLongRunning())
> + {
> + Page page = RequestCycle.get().getResponsePage();
> + if (page != null)
> + {
> + page.setMetaData(WebBeansMetaData.CID,
> conversation.getId());
> + }
> + }
> +
> + //cleanup and deactivate the conversation context
> +
> +
> CurrentManager
> .rootManager
> ().getInstanceByType(ConversationManager.class).cleanupConversation();
> + ConversationContext.INSTANCE.setActive(false);
> + }
> +}
> \ No newline at end of file
>
>
> Property changes on: extensions/trunk/wicket/src/main/java/org/jboss/
> webbeans/wicket/WebBeansWebRequestCycleProcessor.java
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> _______________________________________________
> webbeans-commits mailing list
> webbeans-commits(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/webbeans-commits
--
Pete Muir
http://www.seamframework.org
http://in.relation.to/Bloggers/Pete
15 years, 7 months
[webbeans-dev] Problem in webbeans event handling
by Benjamin Graf
Hi Pete,
I recognized an issue while compiling latest webbeans se extension. Two
unit tests fails because of an nullpointerexception. The reason for this
exception is:
SE finally sends an Shutdown Event which is fired to all observers in
EventManager.notifyObservers.
Finally this method invokes DependentContext.instance().setActive(false);
And there is the problem. If you follow the invokationprocess you'll get
than will get an instance of IsolatedStaticSingletonProvider whose
internal object is null. Maybe this instance was cleaned to early?
By the way IntegerMaangerImplMap in CurrentManager seems to be misspell! :-)
Greets Benjamin
15 years, 7 months
[webbeans-dev] equals() on ConversationImpl
by Clint Popetz
Hi,
Knowing that equals()/hashCode() commits can often lead to month-long
debates, I thought I'd ask first...is it ok to add an equals() on
ConversationImpl that compares cids? The reason I ask is that I want
to put ConversationManager.getLongRunningConversations() into a
<select/> in my wicket example, and the built-in wicket component for
this checks equals() to determine which is option is selected. The
default == test won't work because of proxies. (It also seems
reasonable to me that users would want to stick Conversations in
collections.)
Thanks,
-Clint
15 years, 7 months