Mostrando postagens com marcador Primefaces. Mostrar todas as postagens
Mostrando postagens com marcador Primefaces. Mostrar todas as postagens

quinta-feira, 29 de agosto de 2013

Primepush



One socket to listener the channel and call the javascript function.
<p:socket onMessage="functionName" channel="/notifyTreeMap"  />


The tag remmote command can be used to
<h:form>
          <p:remoteCommand id="test" name="functionName" actionListener="" update="" global="false" />        
 </h:form>

In Menaged Bean,  get context by;
PushContext pushContext = PushContextFactory.getDefault().getPushContext();



To use primepush in jboss the atmosphere dependence is needed.

  <dependency>
            <groupId>org.atmosphere.jboss.as</groupId>
            <artifactId>jboss-as-websockets</artifactId>
            <version>0.5</version>
   </dependency>

segunda-feira, 15 de julho de 2013

Javascript function calling the Managed bean. And passing parameters.


Primefaces provide an component to make action reguest to the managed bean using JavaScript. The remotecomnand can make it for you, using some java script function you can make one request to server side.

Function to call:

<script type="text/javascript">
//Message is a FacesMessage
    function testRemote2(message) {
        var text = message.detail;
        test([{name: 'data', value: text}]);
    }
</script>


Or by CommandLink:
<p:commandLink value = "send"  onclick="test([{name:'data',value:10}]);

 This  jsf command make all for you.
<p:remoteCommand name="test" actionListener="#{viewController .messageRecever}"></p:remoteCommand>
And the the bean class is like this.

@ManagedBean
@SessionScoped
public class ViewController implements Serializable {

public void messageRecever() {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> param = context.getExternalContext().getRequestParameterMap();
        message.add(param.get("data"));
    }



 }

quarta-feira, 10 de julho de 2013

Primefaces grow with socket


In some place in the page puta the grow. Generally the grow is in the form for update with actions. This example make this with javaScript.

<p:growl widgetVar="growMessage" showDetail="true"/>

One socket to listener the channel and call the javascript function.
<p:socket id="socketweb" onMessage="handleMessage"  channel="/notify" />
Now the messages are inserted by the function handleMessage. When the function show() is called the message appear in the client.
  <script type="text/javascript">
            function handleMessage(facesmessage) {
            facesmessage.severity = 'info';
            growMessage.show([facesmessage]);
        }
  </script>

In managed bean:
To get the Context use pushContext MORE.

The send message use FacesMessage and send to client the message.
 public void send() {
        FacesMessage message = new FacesMessage();
        message.setSeverity(FacesMessage.SEVERITY_INFO);
        message.setSummary("Message");
        message.setDetail("Message Detail");
        pushContext.push("notify", message);
}