[jboss-user] [JBoss Seam] - Re: Trinidad PPR/Ajax and Seam

dajevtic do-not-reply at jboss.com
Sun Apr 15 15:40:45 EDT 2007


Mainly I use the following class for consistent dialog handling for trinidad:
package de.livemediagroup.dialog;
  | 
  | import java.util.Hashtable;
  | import java.util.Map;
  | 
  | import org.apache.myfaces.trinidad.context.RequestContext;
  | import org.apache.myfaces.trinidad.event.ReturnEvent;
  | 
  | public final class Dialog {
  | 
  | 	public static final String CONFIRM = "confirm";
  | 	
  | 	public static final String CANCEL = "cancel";
  | 	
  | 	public static Map createReturnParameterMap() {
  | 		return new Hashtable();
  | 	}
  | 	
  | 	@SuppressWarnings("unchecked")
  | 	public static void cancelDialog() {
  | 		RequestContext.getCurrentInstance().returnFromDialog(CANCEL, createReturnParameterMap());
  | 	}
  | 
  | 	@SuppressWarnings("unchecked")
  | 	public static void confirmDialog(Map returnParameters) {
  | 		RequestContext.getCurrentInstance().returnFromDialog(CONFIRM, returnParameters);
  | 	}
  | 
  | 	public static boolean isConfirmed(ReturnEvent event) {
  | 		Object returnValue = event.getReturnValue();
  | 		return ((returnValue != null) && (returnValue.equals(CONFIRM)));		
  | 	}
  | 
  | 	public static boolean isCanceled(ReturnEvent event) {
  | 		Object returnValue = event.getReturnValue();
  | 		return ((returnValue == null) || (returnValue.equals(CANCEL)));		
  | 	}
  | 
  | }
  | 

when wanting to confirm a dialog i use the following code:

  | 	public void saveUser() {
  |     	Map returnParameters = Dialog.createReturnParameterMap();
  |     	returnParameters.put("user", currentUserInformation);
  |     	Dialog.confirmDialog(returnParameters);
  |     }
  | 

a return listener gets activated when returning from my dialog:

  | 	public void processReturn(ReturnEvent event)
  | 			throws AbortProcessingException {
  | 		if (!Dialog.isCanceled(event)) {
  | 			for (Object object : event.getReturnParameters().values()) {
  | 				PersistableObject pObject = (PersistableObject) object;
  | 				saveObject(pObject);
  | 				getEntityManager().flush();
  | 			}
  | 			refresh();
  | 			getNotifier().notifyDialogEnd();
  | 		}
  | 		clearHandledEntity();
  | 	}
  | 

The snippet that activates the dialog, e.g.:

  | <tr:commandLink id="editModeCommand" useWindow="true"
  | 						returnListener="#{model.processReturn}" action="#{model.customize}">
  | 						<f:param name="conversationPropagation" value="join"/>
  | 						<h:graphicImage value="/images/gnome-settings.gif" />
  | 					</tr:commandLink>

getNotifier is a simple, yet powerful goodie, because PPR updates can only occur on components that are below my triggering component. My Notifier is the first UI component so when I trigger it I can also PPR components which are before my commandLink that triggers the dialog.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4037388#4037388

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4037388



More information about the jboss-user mailing list