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>

sábado, 24 de agosto de 2013

EJB3.1


EJB is used to provide services for distributed applications.
Some different configuration type can be used, one example in the code;

@Stateless //State type for the EJB
@LocalBean //Says that this need not local interface
public class Implementation   implements InterfaceRemote {
}

In this case the local method is all in the class Implementation, they don't need annotations.


Some implementations use generics to have less repeated code.
A Good use of  this is for DAO of entity, the class Implementation extends SomeGenericDAO<EntityTO>.
Or a simple use is extends SomeClass only.

One EJB can acess other using the annotation @EJB to inject dependen.
@EJB
private UserBean userBean;


This being updated.........

quinta-feira, 22 de agosto de 2013

Make client action from managed bean.


To add some message to client use addMessage from client session:

FacesContext.getCurrentInstance().addMessage(null, message);



The RequestContext can make some calls to Client side from bean.
RequestContext context = RequestContext.getCurrentInstance();

To execute some Javascript:
context.execute("Javascript_statement");



Example open new page;
String url;
context.execute("window.open('" + url + "', '_blank', 'location=no, status=no, menubar=no, toolbar=no, width=800, height=600')");

The RequestContext can update the client UI:
context.update("formSelectedElementOnMap");

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

Usando jquery


Executar click
jQuery('button[id*="SOME_BUTTON_ID"]').click();
Adicionar conteúdo no input
jQuery('input[id*="SOME_IMPUT_ID"]').val('TEXT');

     SELETORES
Acessando componente pelo id
$("#myDiv")
Acessando pela classe
$(".myClass")
Acessando por um tipo de componente
$("div")

Adicionando uma ação no click
$("#myDiv").click(function(){
});

Boas Praticas

Para prevenir que códigos jquery sejam chamados antes que a pagina seja carregada colocar dentro do evento ready.

$(document).ready(function(){
}); 

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);
}

Jsf Session attributes Map

Find Session scope attributes
Pegar atributos da sessão do usuário

FacesUtils.getFacesContext().getExternalContext().getSessionMap().put()
FacesUtils.getFacesContext().getExternalContext().getSessionMap().remove()
FacesUtils.getFacesContext().getExternalContext().getSessionMap().get()