voyent
Easy Ajax Push Tutorial needs to be updated  XML
Forum Index -> ICEpush General
Author Message
ga2518

Joined: 26/Mar/2007 00:00:00
Messages: 30
Offline


I’m trying to get an outputText component to be updated line-by-line by the server while running a long process, so using ICEpush seems like the best way to accomplish this. I can’t get it to work, and I’m not sure where the problem is.

My first roadblock is the tutorial, it’s written for Servlet 2.5 instead of 3.0. While this may not be serious, my entries in the web.xml may be wrong. My understanding from various messages is that this is the key statement I need in my web.xml:

Code:
<servlet>
 		<servlet-name>Faces Servlet</servlet-name>
 		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
 		<load-on-startup>1</load-on-startup>
 		<async-supported>true</async-supported>
 </servlet>


So when my application starts, ICEpush seems to initialize properly:

Sep 23, 2014 10:36:09 AM org.icepush.servlet.MainServlet <init>
INFO:
ICEsoft Technologies Inc.
ICEpush 3.3.0
Build number: 11
Revision: 34423

Sep 23, 2014 10:36:13 AM org.icepush.servlet.EnvironmentAdaptingServlet <init>
INFO: Adapting to Servlet 3.0 AsyncContext environment
Sep 23, 2014 10:36:13 AM org.icepush.servlet.AsyncAdaptingServlet <init>
INFO: Using Servlet 3.0 AsyncContext


Here are the various pieces of my code:
Code:
 …<f:facet name="second">
 	<h:panelGrid columns="1">
 		<ice:outputText value=“#{backingBean.statusMessage}" escape="false" rendered="true"/>
 	</h:panelGrid>
 </f:facet>
 </ice:panelDivider>
 	<h:commandButton value="Create Folders” disabled="false" actionListener=“#{backingBean.makeChanges}”/>…
 
 
 @ManagedBean(name = BackingBean.BEAN_NAME)
 @CustomScoped(value = "#{window}")
 public class BackingBean implements Serializable {
 	public static final String BEAN_NAME = “backingBean”;
 	private static final String PUSH_GROUP = "MyGroup";
 	final PortableRenderer renderer;
 	private StringBuffer sBuffer = new StringBuffer();
 
 	public BackingBean() {
 		FacesContext fcontext = FacesContext.getCurrentInstance();
 		HttpSession session = (HttpSession)fcontext.getExternalContext().getSession(false);
 		renderer = PushRenderer.getPortableRenderer(session.getServletContext());
 	}
 
 public void makeChanges(ActionEvent event) {
 		new Thread(new Runnable(){
 			public void run(){
 				createFolders();
 			}
 		}).start();
 	}
 
 public void createFolders() {
 	// assume List is initialized
 	for (ListIterator<Folder> iter = cabList.listIterator(); iter.hasNext();) {
 			Folder element = iter.next();
 			
 			folder_name = element.getFolderName();
 			createFolder(folder_name);
 			appendStatusMessage(“Folder “  + folder_name + “ created”);
 	} 
 
 public void appendStatusMessage(String mess) {
 		sBuffer.append(mess);
 		statusMessage = sBuffer.toString();
 		renderer.render(PUSH_GROUP);
 	}
 }


It seems that one needs to make this “PUSH_GROUP” equal to some actual component in your code, but neither the tutorial or other examples seem to explain how to do this. It seems to just be arbitrary text which you can call anything.

What is happening is that nothing at all is being output to the statusMessage. I know the text is being written, because I have a logging statement that shows the exact same text. If I remove the Thread initialization and just call the createFolders() method the text gets written to the statusMessage, but only after the entire function has completed, but then I don’t get line-by-line output.

Any help would be appreciated.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi,
Thanks for the feedback. We'll update the tutorial asap. I think you're just missing the push registration aspect here. It looks like you're correctly making the push, and you're using a PortableRenderer initialized to a final variable so that it can be seen inside your thread. That's all good. But you have to register views or sessions to be included in a push group. You can do this programmatically through the PushRenderer api, or simply add the following tag to your page:

Code:
 <icecore:push group="MyGroup"/>
 


http://www.icesoft.org/wiki/display/ICE/push

You might also want to initialize to initialize things and get the reference to the PortableRenderer in a @PostConstruct method instead of a constructor to make sure things are initialized.

Thanks,
Philip

.
deryk.sinotte


Joined: 26/Oct/2004 00:00:00
Messages: 1008
Offline


Servlet 3.0 shouldn't really be an issue. ICEpush does try to take advantage of the async features in Servlet 3.0 if they are available but that should be done transparently for you.

A push group is basically just a logical "tag" that organizes who should get a notification. You can use it to indicate that you want to push to a single user or many users. I usually think of them as "chat rooms". When sessions are added to a push group it simply indicates to the ICEpush engine which users should receive notifications when a render is called. In your case it appears that every new client would be added to "MyGroup" and when the render is called, everyone in that group would receive a notification that the model had changed in some meaningful way. This would trigger each client to make a JSF request to update their UI based on the differences in the app state. Other than calling render, the rest is done automatically for you.

In your case, I don't see where the current user is added to the push group:

Code:
PushRenderer.addCurrentSession(PUSH_GROUP);


only when render is called:

Code:
renderer.render(PUSH_GROUP);


This step is outlined in the tutorial but perhaps you missed it or didn't copy in that part of your code:

http://www.icesoft.org/wiki/display/ICE/Easy+Ajax+Push#EasyAjaxPush-step8b

If that's not the issue and your app is small enough would it be possible to post it to the thread? I don't see anything obvious up front but if I could actually run it, it might help make things clearer. You can leave out the ICEfaces libs to keep the upload smaller.

Deryk Sinotte
Team Lead
ICEsoft Technologies, Inc.
ga2518

Joined: 26/Mar/2007 00:00:00
Messages: 30
Offline


Thanks Phillip and Deryk. I was missing the tag <icecore:push group="MyGroup"/> and that's what was so confusing about the tutorial.

The group in the tutorial is "colorPage", but there's no icecore:push tag in the color.xhtml page either. I couldn't figure out where 'colorPage' was supposed to go.

It works perfectly now.
 
Forum Index -> ICEpush General
Go to:   
Powered by JForum 2.1.7ice © JForum Team