Author: pete.muir(a)jboss.org
Date: 2008-05-13 14:27:37 -0400 (Tue, 13 May 2008)
New Revision: 8179
Added:
trunk/src/wicket/org/jboss/seam/wicket/international/
trunk/src/wicket/org/jboss/seam/wicket/international/SeamStatusMessagesListener.java
trunk/src/wicket/org/jboss/seam/wicket/international/WicketStatusMessages.java
Modified:
trunk/examples/wicket/
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/BookingListAction.java
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/ChangePasswordAction.java
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Home.html
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.html
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java
trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java
trunk/src/main/org/jboss/seam/faces/FacesMessages.java
trunk/src/main/org/jboss/seam/international/StatusMessages.java
trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
Log:
JBSEAM-2990
Property changes on: trunk/examples/wicket
___________________________________________________________________
Name: svn:ignore
+ exploded-archives
dist
Modified:
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/BookingListAction.java
===================================================================
---
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/BookingListAction.java 2008-05-13
17:15:06 UTC (rev 8178)
+++
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/BookingListAction.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -21,7 +21,7 @@
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
-import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;
@Stateful
@@ -63,7 +63,7 @@
Booking cancelled = em.find(Booking.class, booking.getId());
if (cancelled!=null) em.remove( cancelled );
getBookings();
- FacesMessages.instance().add("Booking cancelled for confirmation number
#{bookingList.booking.id}");
+ StatusMessages.instance().addToControl("body", "Booking cancelled
for confirmation number #{bookingList.booking.id}");
}
// TODO replace this with @Out in Wicket
Modified:
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/ChangePasswordAction.java
===================================================================
---
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/ChangePasswordAction.java 2008-05-13
17:15:06 UTC (rev 8178)
+++
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/ChangePasswordAction.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -13,6 +13,7 @@
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
+import org.jboss.seam.international.StatusMessages;
@Stateful
@Scope(EVENT)
@@ -26,14 +27,13 @@
@PersistenceContext
private EntityManager em;
- // TODO JBSEAM-2515
- //@In
- //private FacesMessages facesMessages;
+ @In(create=true)
+ private StatusMessages statusMessages;
public void changePassword()
{
user = em.merge(user);
- //facesMessages.add("Password updated");
+ statusMessages.add("Password updated");
}
@Remove
Modified:
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java
===================================================================
---
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java 2008-05-13
17:15:06 UTC (rev 8178)
+++
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/HotelBookingAction.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -18,6 +18,7 @@
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.core.Events;
+import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;
@Stateful
@@ -39,9 +40,8 @@
@Out(required=false)
private Booking booking;
- // TODO JBSEAM-2515
- //@In
- //private FacesMessages facesMessages;
+ @In(create=true)
+ private StatusMessages statusMessages;
@In
private Events events;
@@ -74,12 +74,12 @@
calendar.add(Calendar.DAY_OF_MONTH, -1);
if ( booking.getCheckinDate().before( calendar.getTime() ) )
{
- //facesMessages.addToControl("checkinDate", "Check in date must
be a future date");
+ statusMessages.addToControl("checkinDate", "Check in date must be
a future date");
bookingValid=false;
}
else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
{
- //facesMessages.addToControl("checkoutDate", "Check out date must
be later than check in date");
+ statusMessages.addToControl("checkoutDate", "Check out date must
be later than check in date");
bookingValid=false;
}
else
@@ -97,7 +97,7 @@
public void confirm()
{
em.persist(booking);
- //facesMessages.add("Thank you, #{user.name}, your confimation number for
#{hotel.name} is #{booking.id}");
+ statusMessages.add("Thank you, #{user.name}, your confimation number for
#{hotel.name} is #{booking.id}");
log.info("New booking: #{booking.id} for #{user.username}");
events.raiseTransactionSuccessEvent("bookingConfirmed");
}
Modified:
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java
===================================================================
---
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java 2008-05-13
17:15:06 UTC (rev 8178)
+++
trunk/examples/wicket/src/action/org/jboss/seam/example/wicket/action/RegisterAction.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -13,6 +13,7 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.international.StatusMessages;
@Stateful
@Scope(EVENT)
@@ -25,9 +26,8 @@
@PersistenceContext
private EntityManager em;
- //TODO JBSEAM-2515
- //@In
- //private FacesMessages facesMessages;
+ @In(create=true)
+ private StatusMessages statusMessages;
private String verify;
@@ -42,24 +42,24 @@
if (existing.size()==0)
{
em.persist(user);
- //facesMessages.add("Successfully registered as
#{user.username}");
+ statusMessages.addToControl("login", "Successfully registered
as #{user.username}");
registered = true;
}
else
{
- //facesMessages.addToControl("username", "Username
#{user.username} already exists");
+ statusMessages.addToControl("username", "Username
#{user.username} already exists");
}
}
else
{
- //facesMessages.addToControl("verify", "Re-enter your
password");
+ statusMessages.addToControl("verify", "Re-enter your
password");
verify=null;
}
}
public void invalid()
{
- //facesMessages.add("Please try again");
+ statusMessages.add("Please try again");
}
public boolean isRegistered()
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-05-13
17:15:06 UTC (rev 8178)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Book.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -35,7 +35,6 @@
import org.apache.wicket.validation.ValidationError;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.security.Restrict;
-import org.jboss.seam.core.Conversation;
import org.jboss.seam.example.wicket.action.Booking;
import org.jboss.seam.example.wicket.action.HotelBooking;
@@ -134,10 +133,6 @@
{
setResponsePage(Confirm.class);
}
- else
- {
- error(new ValidationError().setMessage("Error"));
- }
}
@Override
@@ -153,6 +148,5 @@
protected void onBeforeRender()
{
super.onBeforeRender();
- System.out.println("cid " + Conversation.instance().getId());
}
}
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Home.html
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Home.html 2008-05-13
17:15:06 UTC (rev 8178)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Home.html 2008-05-13
18:27:37 UTC (rev 8179)
@@ -19,7 +19,6 @@
<div>
<label for="username">Login Name</label>
<input wicket:id="username" style="width: 175px;"/>
- <div class="errors"><h:message
for="username"/></div>
</div>
<div>
<label for="password">Password</label>
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.html
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.html 2008-05-13
17:15:06 UTC (rev 8178)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.html 2008-05-13
18:27:37 UTC (rev 8179)
@@ -9,9 +9,9 @@
<!-- content -->
<div class="section">
+ <span class="errors" wicket:id="messages" />
+
<form wicket:id="searchCriteria">
-
- <span class="errors" wicket:id="messages" />
<h1>Search Hotels</h1>
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java 2008-05-13
17:15:06 UTC (rev 8178)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Main.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -63,9 +63,9 @@
private HotelSearchForm hotelSearchForm;
private WebMarkupContainer hotels;
private Component noHotelsFound;
+ private Component messages;
-
public Main(final PageParameters parameters)
{
Template body = new Template("body");
@@ -73,6 +73,9 @@
hotelSearchForm = new HotelSearchForm("searchCriteria");
body.add(hotelSearchForm);
+ messages = new ComponentFeedbackPanel("messages",
this).setOutputMarkupId(true);
+ add(messages);
+
/*
* Hotel Search results
*/
@@ -120,7 +123,8 @@
@Override
public boolean isVisible()
{
- return Identity.instance().isLoggedIn() &&
hotelSearch.getHotels().size() > 0;
+ return true;
+ //return Identity.instance().isLoggedIn() &&
hotelSearch.getHotels().size() > 0;
}
};
@@ -226,8 +230,6 @@
add(new TextField("searchString", new PropertyModel(hotelSearch,
"searchString")));
List<Integer> pageSizes = Arrays.asList(new Integer[] { 5, 10, 20 });
add(new DropDownChoice("pageSize", new PropertyModel(this,
"pageSize"), pageSizes));
- final Component messages = new ComponentFeedbackPanel("messages",
this).setOutputMarkupId(true);
- add(messages);
add(new IndicatingAjaxButton("submit", this)
{
Modified: trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java
===================================================================
--- trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java 2008-05-13
17:15:06 UTC (rev 8178)
+++ trunk/examples/wicket/src/web/org/jboss/seam/example/wicket/Register.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -26,7 +26,9 @@
public Register()
{
- add(new RegisterForm("registration"));
+ Form registerForm = new RegisterForm("registration");
+ add(registerForm);
+ registerForm.add(new ComponentFeedbackPanel("messages", this));
}
public class RegisterForm extends Form
@@ -44,7 +46,6 @@
FormComponent verify = new
PasswordTextField("verify").setRequired(true);
add(new FormInputBorder("passwordDecorate", "Password",
password , new PropertyModel(user, "password")));
add(new FormInputBorder("verifyDecorate", "Verify Password",
verify, new PropertyModel(register, "verify")));
- add(new ComponentFeedbackPanel("messages", this));
add(new EqualPasswordInputValidator(password, verify));
}
@@ -52,7 +53,10 @@
protected void onSubmit()
{
register.register();
- setResponsePage(Home.class);
+ if (register.isRegistered())
+ {
+ setResponsePage(Home.class);
+ }
}
}
Modified: trunk/src/main/org/jboss/seam/faces/FacesMessages.java
===================================================================
--- trunk/src/main/org/jboss/seam/faces/FacesMessages.java 2008-05-13 17:15:06 UTC (rev
8178)
+++ trunk/src/main/org/jboss/seam/faces/FacesMessages.java 2008-05-13 18:27:37 UTC (rev
8179)
@@ -49,7 +49,8 @@
{
for ( StatusMessage statusMessage: entry.getValue() )
{
- FacesContext.getCurrentInstance().addMessage( entry.getKey(),
toFacesMessage(statusMessage) );
+ String clientId = getClientId(entry.getKey());
+ FacesContext.getCurrentInstance().addMessage( clientId,
toFacesMessage(statusMessage) );
}
}
clear();
@@ -128,11 +129,10 @@
}
}
- @Override
/**
* Calculate the JSF client ID from the provided widget ID
*/
- protected String getClientId(String id)
+ private String getClientId(String id)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
return getClientId( facesContext.getViewRoot(), id, facesContext);
Modified: trunk/src/main/org/jboss/seam/international/StatusMessages.java
===================================================================
--- trunk/src/main/org/jboss/seam/international/StatusMessages.java 2008-05-13 17:15:06
UTC (rev 8178)
+++ trunk/src/main/org/jboss/seam/international/StatusMessages.java 2008-05-13 18:27:37
UTC (rev 8179)
@@ -52,6 +52,16 @@
keyedMessages.clear();
}
+ public void clearKeyedMessages(String id)
+ {
+ keyedMessages.remove(id);
+ }
+
+ public void clearGlobalMessages()
+ {
+ messages.clear();
+ }
+
/**
* Add a status message, looking up the message in the resource bundle
* using the provided key. If the message is found, it is used, otherwise,
@@ -100,16 +110,15 @@
public void run()
{
StatusMessage message = new StatusMessage(severity, key, null,
messageTemplate, null, params);
- String clientId = getClientId(id);
- if (keyedMessages.containsKey(clientId))
+ if (keyedMessages.containsKey(id))
{
- keyedMessages.get(clientId).add(message);
+ keyedMessages.get(id).add(message);
}
else
{
List<StatusMessage> list = new
ArrayList<StatusMessage>();
list.add(message);
- keyedMessages.put(clientId, list);
+ keyedMessages.put(id, list);
}
}
@@ -117,8 +126,6 @@
);
}
-
- protected abstract String getClientId(String id);
/**
* Create a new status message, with the messageTemplate is as the message.
@@ -371,7 +378,7 @@
}
}
- private void doRunTasks()
+ protected void doRunTasks()
{
if (tasks!=null)
{
Modified: trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-05-13 17:15:06 UTC
(rev 8178)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-05-13 18:27:37 UTC
(rev 8179)
@@ -15,6 +15,7 @@
import
org.apache.wicket.request.target.component.listener.IListenerInterfaceRequestTarget;
import org.jboss.seam.core.Conversation;
import org.jboss.seam.core.Manager;
+import org.jboss.seam.wicket.international.SeamStatusMessagesListener;
import org.jboss.seam.wicket.ioc.SeamInjectionListener;
/**
@@ -113,6 +114,7 @@
super.init();
inititializeSeamSecurity();
initializeSeamInjection();
+ initializeSeamStatusMessages();
}
/**
@@ -135,6 +137,14 @@
{
addComponentInstantiationListener(new SeamInjectionListener());
}
+
+ /**
+ * Add Seam status message transport support to youur app.
+ */
+ protected void initializeSeamStatusMessages()
+ {
+ addComponentOnBeforeRenderListener(new SeamStatusMessagesListener());
+ }
protected abstract Class getLoginPage();
Added:
trunk/src/wicket/org/jboss/seam/wicket/international/SeamStatusMessagesListener.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/international/SeamStatusMessagesListener.java
(rev 0)
+++
trunk/src/wicket/org/jboss/seam/wicket/international/SeamStatusMessagesListener.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -0,0 +1,64 @@
+package org.jboss.seam.wicket.international;
+
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.application.IComponentOnBeforeRenderListener;
+import org.jboss.seam.international.StatusMessage;
+
+
+public class SeamStatusMessagesListener implements IComponentOnBeforeRenderListener
+{
+
+ public void onBeforeRender(Component component)
+ {
+
+ WicketStatusMessages wicketStatusMessages = WicketStatusMessages.instance();
+ wicketStatusMessages.onBeforeRender();
+
+ if (component instanceof Page)
+ {
+ // If the component is the page, then we also add global messages
+ List<StatusMessage> statusMessages =
wicketStatusMessages.getGlobalMessages();
+ if (statusMessages != null)
+ {
+ for (StatusMessage statusMessage: statusMessages)
+ {
+ addFeedbackMessage(statusMessage, component);
+ }
+ }
+ wicketStatusMessages.clearGlobalMessages();
+ }
+
+ List<StatusMessage> statusMessages =
wicketStatusMessages.getKeyedMessages(component.getId());
+ if (statusMessages != null)
+ {
+ for (StatusMessage statusMessage: statusMessages)
+ {
+ addFeedbackMessage(statusMessage, component);
+ }
+ wicketStatusMessages.clearKeyedMessages(component.getId());
+ }
+ }
+
+ private void addFeedbackMessage(StatusMessage statusMessage, Component component)
+ {
+ switch (statusMessage.getSeverity())
+ {
+ case ERROR:
+ component.error(statusMessage.getSummary());
+ break;
+ case FATAL:
+ component.fatal(statusMessage.getSummary());
+ break;
+ case INFO:
+ component.info(statusMessage.getSummary());
+ break;
+ case WARN:
+ component.warn(statusMessage.getSummary());
+ break;
+ }
+ }
+
+}
Property changes on:
trunk/src/wicket/org/jboss/seam/wicket/international/SeamStatusMessagesListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/international/WicketStatusMessages.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/international/WicketStatusMessages.java
(rev 0)
+++
trunk/src/wicket/org/jboss/seam/wicket/international/WicketStatusMessages.java 2008-05-13
18:27:37 UTC (rev 8179)
@@ -0,0 +1,48 @@
+package org.jboss.seam.wicket.international;
+
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+
+import java.util.List;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.international.StatusMessage;
+import org.jboss.seam.international.StatusMessages;
+
+(a)Scope(ScopeType.CONVERSATION)
+(a)Name(StatusMessages.COMPONENT_NAME)
+@Install(precedence=FRAMEWORK,
classDependencies="org.apache.wicket.Application")
+@BypassInterceptors
+public class WicketStatusMessages extends StatusMessages
+{
+
+ public void onBeforeRender()
+ {
+ doRunTasks();
+ }
+
+ public List<StatusMessage> getKeyedMessages(String id)
+ {
+ return instance().getKeyedMessages().get(id);
+ }
+
+ public List<StatusMessage> getGlobalMessages()
+ {
+ return instance().getMessages();
+ }
+
+ public static WicketStatusMessages instance()
+ {
+ if ( !Contexts.isConversationContextActive() )
+ {
+ throw new IllegalStateException("No active conversation context");
+ }
+ return (WicketStatusMessages) Component.getInstance(StatusMessages.COMPONENT_NAME,
ScopeType.CONVERSATION);
+ }
+
+}
Property changes on:
trunk/src/wicket/org/jboss/seam/wicket/international/WicketStatusMessages.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain