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

Nenhum comentário: