[seam-commits] Seam SVN: r9217 - in trunk: examples/wicket/src/web/org/jboss/seam/example/wicket and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Oct 7 10:00:17 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-10-07 10:00:17 -0400 (Tue, 07 Oct 2008)
New Revision: 9217
Added:
trunk/src/wicket/org/jboss/seam/wicket/SeamComponentInstantiationListener.java
trunk/src/wicket/org/jboss/seam/wicket/annotations/
trunk/src/wicket/org/jboss/seam/wicket/annotations/NoConversationPage.java
Modified:
trunk/doc/Seam_Reference_Guide/en-US/Wicket.xml
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java
trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
Log:
JBSEAM-3516
Modified: trunk/doc/Seam_Reference_Guide/en-US/Wicket.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Wicket.xml 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/doc/Seam_Reference_Guide/en-US/Wicket.xml 2008-10-07 14:00:17 UTC (rev 9217)
@@ -122,9 +122,6 @@
Seam will automatically apply the restriction to any nested
classes.
</para>
- <para>
- TODO - Implement this (See JBSEAM-3192)
- </para>
</tip>
<para>
@@ -156,6 +153,16 @@
};]]></programlisting>
<para>
+ You may have pages in your application which can only be accessed
+ when the user has a long-running conversation active. To enforce
+ this you can use the <code>@NoConversationPage</code> annotation:
+ </para>
+
+ <programlisting><![CDATA[@Restrict
+ at NoConversationPage(Main.class)
+public class Hotel extends WebPage {]]></programlisting>
+
+ <para>
If you want to further decouple your application classes, you can
use Seam events. Of course, you can raise an event using
<code>Events.instance().raiseEvent("foo")</code>. Alternatively, you
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -19,8 +19,10 @@
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.example.wicket.action.Booking;
import org.jboss.seam.example.wicket.action.HotelBooking;
+import org.jboss.seam.wicket.annotations.NoConversationPage;
@Restrict
+ at NoConversationPage(Main.class)
public class Book extends WebPage
{
@@ -42,7 +44,6 @@
add(body);
body.add(new HotelViewPanel("hotelView", booking.getHotel()));
body.add(new HotelBookingForm("booking"));
-
}
public class HotelBookingForm extends Form
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Confirm.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -15,8 +15,10 @@
import org.jboss.seam.core.Conversation;
import org.jboss.seam.example.wicket.action.Booking;
import org.jboss.seam.example.wicket.action.HotelBooking;
+import org.jboss.seam.wicket.annotations.NoConversationPage;
@Restrict
+ at NoConversationPage(Main.class)
public class Confirm extends WebPage
{
@@ -67,11 +69,4 @@
add(body);
}
- @Override
- protected void onBeforeRender()
- {
- super.onBeforeRender();
- System.out.println("cid " + Conversation.instance().getId());
- }
-
}
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Hotel.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -8,8 +8,10 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.example.wicket.action.HotelBooking;
+import org.jboss.seam.wicket.annotations.NoConversationPage;
@Restrict
+ at NoConversationPage(Main.class)
public class Hotel extends WebPage
{
Added: trunk/src/wicket/org/jboss/seam/wicket/SeamComponentInstantiationListener.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamComponentInstantiationListener.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamComponentInstantiationListener.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -0,0 +1,38 @@
+package org.jboss.seam.wicket;
+
+import org.apache.wicket.AbortException;
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.application.IComponentInstantiationListener;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.international.StatusMessage;
+import org.jboss.seam.international.StatusMessages;
+
+public class SeamComponentInstantiationListener implements IComponentInstantiationListener
+{
+
+ public void onInstantiation(Component component)
+ {
+ if (!Manager.instance().isLongRunningConversation())
+ {
+ WicketComponent<?> wicketComponent = WicketComponent.getInstance(component.getClass());
+ if (wicketComponent != null)
+ {
+ Class<? extends Page> noConversationPage = wicketComponent.getNoConversationPage();
+ if (noConversationPage != null)
+ {
+ final RequestCycle cycle = RequestCycle.get();
+ StatusMessages.instance().addFromResourceBundleOrDefault(
+ StatusMessage.Severity.WARN,
+ "org.jboss.seam.NoConversation",
+ "The conversation ended or timed"
+ );
+ cycle.redirectTo(component.getPageFactory().newPage(noConversationPage));
+ throw new AbortException();
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/SeamComponentInstantiationListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -111,6 +111,7 @@
super.init();
inititializeSeamSecurity();
initializeSeamStatusMessages();
+ addComponentInstantiationListener(new SeamComponentInstantiationListener());
}
/**
Modified: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-10-07 12:11:07 UTC (rev 9216)
+++ trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -14,6 +14,7 @@
import java.util.List;
import java.util.Set;
+import org.apache.wicket.Page;
import org.apache.wicket.util.string.Strings;
import org.jboss.seam.Component;
import org.jboss.seam.Namespace;
@@ -37,6 +38,7 @@
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.security.Identity;
+import org.jboss.seam.wicket.annotations.NoConversationPage;
import org.jboss.seam.wicket.ioc.BijectedAttribute;
import org.jboss.seam.wicket.ioc.BijectedField;
import org.jboss.seam.wicket.ioc.BijectedMethod;
@@ -98,6 +100,8 @@
boolean anyMethodHasRaiseEvent = false;
+ private Class<? extends Page> noConversationPage;
+
public Class<?> getType()
{
return type;
@@ -150,18 +154,9 @@
{
this.type = type;
this.enclosingType = type.getEnclosingClass();
- if (enclosingType != null)
+ if (this.enclosingType != null)
{
- Class<?> c = enclosingType.getEnclosingClass();
- int i = 0;
- while (c != null)
- {
- c = c.getEnclosingClass();
- i++;
- }
- this.enclosingInstanceVariableName = "this$" + i;
log.info("Class: " + type + ", enclosed by " + enclosingType);
- log.trace("[" + type + "] enclosing instance variable: " + enclosingInstanceVariableName);
}
else
{
@@ -170,8 +165,6 @@
scan();
- scanRestrictions();
-
initInterceptors();
Contexts.getApplicationContext().set(getName(), this);
@@ -180,6 +173,7 @@
private void scan()
{
Class clazz = type;
+ scanClassEnclosureHierachy();
for (Method method : clazz.getDeclaredMethods())
{
add(method);
@@ -194,10 +188,10 @@
}
}
- private void scanRestrictions()
+ private void scanClassEnclosureHierachy()
{
Class cls = type;
-
+ int i = 0;
while (cls != null)
{
for (Annotation annotation : cls.getAnnotations())
@@ -214,11 +208,23 @@
if (restrictions == null) restrictions = new HashSet<String>();
restrictions.add("#{identity.hasRole('" +
annotation.annotationType().getSimpleName().toLowerCase() + "')}");
- }
+ }
+
+ if (annotation instanceof NoConversationPage)
+ {
+ NoConversationPage noConversationPage = (NoConversationPage) annotation;
+ this.noConversationPage = noConversationPage.value();
+ }
}
cls = cls.getEnclosingClass();
+ i++;
}
+
+ if (i > 1)
+ {
+ this.enclosingInstanceVariableName = "this$" + (i - 2);
+ }
}
public void checkRestrictions()
@@ -504,4 +510,9 @@
conversationManagementMembers.contains(member);
}
+ public Class<? extends Page> getNoConversationPage()
+ {
+ return noConversationPage;
+ }
+
}
Added: trunk/src/wicket/org/jboss/seam/wicket/annotations/NoConversationPage.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/annotations/NoConversationPage.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/annotations/NoConversationPage.java 2008-10-07 14:00:17 UTC (rev 9217)
@@ -0,0 +1,20 @@
+package org.jboss.seam.wicket.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.wicket.Page;
+
+ at Target(TYPE)
+ at Retention(RUNTIME)
+ at Documented
+public @interface NoConversationPage
+{
+
+ Class<? extends Page> value();
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/annotations/NoConversationPage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the seam-commits
mailing list