PrimePush using dataTable with atmosphere

Posted: November 13, 2012 in web

No need for a jetty server.

xhtml:



			<p:dataTable editable="true" value="#{bean.cars}" var="car" id="lazypanel">
				<p:ajax event="rowEdit" listener="#{bean.onEdit}" />
				<p:column headerText="ID">
					<h:outputText value="#{car.id}" />
				</p:column>
				<p:column headerText="Car Model">
					<h:outputText value="#{car.model}" />
					<f:facet name="footer">
						<p:inputText value="#{car.model}" />
					</f:facet>
				</p:column>
				<p:column headerText="Options" style="width:50px;white-space:nowrap;">
            		<p:rowEditor />
            		<p:commandLink value="Delete" process="@this" style="margin-left:10px" actionListener="#{bean.onDelete(car)}" />
            		<f:facet name="footer">
						<p:commandButton actionListener="#{bean.onAdd}" value="Add" />
					</f:facet>
        		</p:column>  				
			</p:dataTable>
			<p:remoteCommand process="@this" name="lazyload" update="lazypanel" />
		</h:form>
		<p:socket onMessage="lazyload" channel="/counter" />
		

pom:


 		<dependency>
        	     <groupId>org.primefaces</groupId>
	              <artifactId>primefaces</artifactId>
	              <version>3.4</version>
	        </dependency>
		<dependency>
      			<groupId>org.atmosphere</groupId>
	      		<artifactId>atmosphere-runtime</artifactId>
	      		<version>1.0.0.RC1</version>
		</dependency>
		

web.xml:


		<servlet>
		      	<servlet-name>Push Servlet</servlet-name>
		        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
			<load-on-startup>1</load-on-startup>
	 		<async-supported>true</async-supported>  
		</servlet>
	    	<servlet-mapping>
	        	<servlet-name>Push Servlet</servlet-name>
		        <url-pattern>/primepush/*</url-pattern>
	    	</servlet-mapping>
		

Backing Bean:


    public void onEdit(RowEditEvent event) {
        Car car = (Car) event.getObject();
        someService.editCar(Car);
        push();
    }

    public void onAdd() {
        someService.addCar(newCar);
        push();
    }

    public void onDelete(Car car) {
        someService.deleteCar(car);
        push();
    }

    private void push() {
        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
        pushContext.push("/counter", null);
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s