* 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! *

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!

Nenhum comentário: