* Visite o ALJUG - http://aljug.blogspot.com - Noticias sobre a comunidade java alagoana e do mundo * Visite o blog Mundo Gamificado www.mundogamificado.com.br - E vamos mudar o mundo! *

quarta-feira, 15 de julho de 2015

Dynamic components Primefaces - Part Two

Hello guys, let's continue with the dynamic components through the bean.

As we have stated the panelGrid component in the bean builder and as we have already created the code in view, go to next step.

let's make a method called criarPanel (); , Void even as below:


 public void createPanel(){ } 

Let's put it inside the InputText and OutputLabel. If you want to create more than one, then use the FOR repeating structure, for example, want to create six components, then we will use as follows:


 for(int i= 0; i < 6; i++){
  //Code, which will be explained below.
}

Within this is we will assign value to components for this we must get the context for that there is FacesContext, the javax.faces.context.FacesContext package, with getCurrentInstance() method as follows:

FacesContext.getCurrentInstance().getApplication().createComponent(OutputLabel.COMPONENT_TYPE);

In the code above we take the context, your application so we created the component and within the createComponent method declare which component we want, in this case the OutputLabel, only that all this code is not the OutputLabel type and so we have to cast.


 
opl = (OutputLabel) FacesContext.getCurrentInstance().getApplication().createComponent(OutputLabel.COMPONENT_TYPE);


in = (InputText) FacesContext.getCurrentInstance().getApplication().createComponent(InputText.COMPONENT_TYPE);

Then we have to get separate first the current context, then the context of the expression Language ELContext after the application in order to declare a factory of expression, as we can see in the code below:


context = FacesContext.getCurrentInstance();

elContext = context.getELContext();

Application app = context.getApplication();

ExpressionFactory expressionFactory = app.getExpressionFactory();


With this we are almost over for the post not be so great, let's stop here and continue next week.

Any questions can make a comment that I'll be happy to answer even more!

domingo, 12 de julho de 2015

Componentes Dinâmicos com Primefaces - Parte 2

Olá pessoal, vamos continuar com os componentes dinâmicos através do bean.

Como já declaramos o componente PanelGrid no construtor do bean e como já criamos o código na view, vamos para próximo passo.

vamos fazer um metodo chamado criarPanel(); , void mesmo como abaixo:


 public void criarPanel(){ } 

Nele vamos colocar dentro o InputText e OutputLabel. Se quiser criar mais de um, então use a estrutura de repetição FOR, por exemplo, quero criar 6 componentes, então usaremos da seguinte forma:


 for(int i= 0; i < 6; i++){
  //Código, que vai ser explicado abaixo.
}

Dentro deste for iremos atribuir valor aos componentes para isso devemos pegar o contexto, para isso existe o FacesContext, do pacote javax.faces.context.FacesContext, com o método getCurrentInstance() como abaixo:

FacesContext.getCurrentInstance().getApplication().createComponent(OutputLabel.COMPONENT_TYPE);

No código acima pegamos o contexto, sua aplicação com isso criamos o componente e dentro do metodo createComponent declaramos qual o componente que queremos, neste caso o OutputLabel, só que todo esse código não é do tipo OutputLabel e por isso temos que fazer um cast.


 
opl = (OutputLabel) FacesContext.getCurrentInstance().getApplication().createComponent(OutputLabel.COMPONENT_TYPE);


in = (InputText) FacesContext.getCurrentInstance().getApplication().createComponent(InputText.COMPONENT_TYPE);

Depois temos que pegar separado, primeiro o contexto atual, depois o contexto da expression Language o ELContext, depois a aplicação para poder decalrar uma fabrica de expressão, como podemos ver no código abaixo:


context = FacesContext.getCurrentInstance();

elContext = context.getELContext();

Application app = context.getApplication();

ExpressionFactory expressionFactory = app.getExpressionFactory();


Com isso já estamos quase acabando, para o post não ficar tão grande, vamos parar por aqui e continuar na próxima semana.

Qualquer dúvida pode fazer um comentário que eu terei o maior prazer de responder, até mais!

terça-feira, 7 de julho de 2015

Maven e JSF 2 OutputStyleSheet, OutputScript

Olá pessoal,

antes de continuar com o post dos componentes dinâmicos, venho aqui postar ago que estava apanhando para fazer funcionar e só conseguir agora, já estava com dois dias só na tentativa e nada.

Como agora estou fazendo só projetos com maven eu não sabia antes para referênciar os dois componentes, outputStyleSheet e outputScript,  eu criava uma pasta resousces em Páginas Web, criava as subpastas para ficar organizado e fazia a referência na página JSF, pois bem, no maven o projeto já vem tudo subdivido, pelo menos no eclipse, na pasta Java Resources há uma pagina src/main/resources, que eu fiz a mesma organização anterior, porém existe a webapp, pura desatenção.

Quando quiserem refereniciar com o h:outputScript ou h:outputStyleSheet em umprojeto Maven, basta criar uma subpasta resources na webapp e subpastas para organizar como css, js, font e image e na página JSF fazer a referência como abaixo:


  <h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
  <h:outputScript library="js" name="slide.js"></h:outputScript>    



E eu me "brigando" para fazer funcionar.


Valeu pessoal espero ter ajudado com este post!

sábado, 4 de julho de 2015

Dynamic components with Primefaces - Part One

Hello guys,

I am here to write another post that I think will be very useful for when I needed to, I found everything very tailored, one part in a post, elsewhere in another post and so on. I want to remind that I do here components created through the bean, for code and called on the binding tag of JSF components and will use Primefaces, but can use the same way to the jsf own components that works the same way.

What is the idea?

The idea is to create a panel with a number choosing outputLabel and inputText.

So what variables need?


We will need the variables below:


FacesContext context; 
ELContext elContext; 
private InputText in;
private OutputLabel opl;
private PanelGrid panel;



We will need to take the context and also OutputLabel and InputText, without forgetting the panelGrid.

Packets that are the components are:


import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.outputlabel.OutputLabel;
import org.primefaces.component.panelgrid.PanelGrid;


Okay, so we have the components in the bean, now we need to know if it will actually work to create, so the bean builder declare:


panel = new PanelGrid(); (1) 
panel.setId("pnlDinamico"); (2) 
panel.setColumns(2); (3)



Above we started creating the panel (1), we set his id (2), this case is unique because it is just a panel and declare the number of column that was in view would be that way:


<p:panelgrid columns="2" id="pnlDinamico"></p:panelgrid>



To see if it worked really must put the following code:

<p:panelGrid binding="#{bean.panel}">
 <f:facet name="header"> 
      Panel Dinamico 
 </f:facet> 
</p:panelGrid>



Ready with that vcoê code will display a panelGrid without any data only named Dynamic Panel. In the next post we continue. Until then!

Continue in the part two!

Componentes Dinâmicos com Primefaces - Parte 1

Olá pessoal,

Estou aqui para escrever mais um post que acho que vai ser bastante útil, pois quando eu precisei, achei tudo muito costurado, uma parte em um post, outra parte em outro post e assim por diante. Quero lembrar que vou fazer aqui componentes criados através do bean, por código e chamado na tag binding dos componentes do JSF e usarei o primefaces, mas podem usar da mesma forma para componentes do próprio jsf que funciona da mesma forma.

Qual será a ideia?


A ideia é criar um painel com um número a escolha de outputLabel e inputText.

Então que variáveis precisamos?

Precisaremos das variáveis abaixo:

 FacesContext context;
 ELContext elContext;
 private InputText in;
 private OutputLabel opl;
 private PanelGrid panel;

Precisaremos pegar o contexto e também os OutputLabel e InputText, sem esquecer do PanelGrid.

Os pacotes que estão os componentes são:

import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.outputlabel.OutputLabel;
import org.primefaces.component.panelgrid.PanelGrid;


Pronto, com isso temos os componentes no bean, agora precisamos saber se realmente vai funcionar a criação, por isso no construtor do bean declaramos:


        panel = new PanelGrid(); (1)
        panel.setId("pnlDinamico"); (2)
        panel.setColumns(2); (3)

Acima inciamos criando o Painel (1), setamos o id dele (2), neste caso é único, pois é um painel apenas e declaramos o número de coluna que se fosse na view seria desta maneira:


<p:panelgrid columns="2" id="pnlDinamico"></p:panelgrid>

Para ver se realmente funcionou devemos colocar o seguinte código:


<p:panelGrid binding="#{bean.panel}">
<f:facet name="header">
    Panel Dinamico
</f:facet>
</p:panelGrid>


Pronto com esse código vcoê vai visualizar um panelgrid sem nenhum dado somente com o nome Panel Dinâmico.

No próximo post a gente continua. Até lá!

Link para parte 2