* 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, 1 de agosto de 2015

Dynamic components Primefaces - Final Part

Hello everybody, we go to the end of the development of dynamic components Primefaces, I reiterate here that the same way I'm doing with the components of Primefaces, is also done with the components of jsf HtmOutputText and HtmlInputText.

So let's continue, we in the statement below:



 expressionFactory = app.getExpressionFactory();


Recalling that the expressionFactory is to create a factory of EL expression and thus be able to declare the expression as we in the JSF bean.variavel #{bean.variavel}.


Then we instance created with the set values ​​for the components such as the value and the OutputLabel For longer concatenating with InputText ID below:
 opl.setValue ("Field" + (z + 1) + "");
            opl.setId ("lbcampo" + z);
            opl.setFor ("campoID" + z);
            in InputText = new ();
            in.setId ("campoID" + z);
            in.setSize (2);



You can're asking because only instantiated or created a new instance for the inputText, remember that we include expressionLanguage this component and so we must make this action if it does not do that would show the NullPointerException. Done with that we know that according to the value of Z will field 1,2,3,4 ...
 < p:outputLabel value="Field 1" id="lbcampo0" for="campoID0" /> 

And we know that temporarily inputText will
 < p:inputText id="campoID0" size="2" / > 

Now let's put the icing on the cake, that is, we include the expression for the component to take the value in view and to make it as below:
ValueExpression ve = expressionFactory.createValueExpression (elContext, "#{bean.campo[" + z + "]},"String.class);

See who now declare ValueExpression with this we are adding what accustomed to only the view, include a parameter to capture the value that the user typed. Note that is a expressionFactory creating value taking the context and set the class that will have value in the view, in this case the value is a string, but can be changed according to your need. Now we must add the ValueExpression to be included in inputText component
 in.setValueExpression ("value", ve); 

The name value must be placed always as it represents the value of the tag inputText component and a variable ve which is the EL. To give the final touch we should add the components in the panel we created in the beginning as follows:
panel.getChildren().add(opl).;
            panel.getChildren().add(in).;

With this added dynamic components within the panel.

So this is personal, any questions I am available only comment here and then send an e-mail. To the next!

Componentes Dinâmicos com Primefaces - Parte 3(Final)

Olá pessoal, vamos para parte final do desenvolvimento dos componentes dinâmicos com primefaces, reitero aqui que da mesma forma que estou fazendo com os componentes do primefaces, também é feito com os componentes do jsf HtmOutputText e HtmlInputText.

Então vamos continuar, ficamos na parte da declaração abaixo:



expressionFactory = app.getExpressionFactory();


Lembrando que o expressionFactory é para criar uma fabrica de expressão EL e assim poder declarar a expressão como costumamos no JSF #{bean.variavel}.


Então com a instância criada vamos definir valores para os componentes como, por exemplo o valor e o For do OutputLabel já concatenando com a ID do InputText, abaixo:
 opl.setValue("Campo " + (z + 1) + ": ");
            opl.setId("lbcampo" + z);
            opl.setFor("campoID" + z);
            in = new InputText();
            in.setId("campoID" + z);
            in.setSize(2);



Você pode está perguntando porque só instanciou ou criou uma nova instância para o inputText, lembra que vamos incluir a expressionLanguage neste componente e por isso devemos fazer essa ação, caso não fizesse isso iria aparecer o NullPointerException. Pronto com isso já sabemos que de acordo com o valor do Z teremos Campo 1,2,3,4...
 <p:outputLabel value="Campo 1" id="lbcampo0" for="campoID0"/>

E também sabemos temporariamente que o inputText ficará
<p:inputText id="campoID0" size="2"/>

Agora vamos colocar a cereja no bolo, ou seja, vamos incluir a expressão para que o componente pegue o valor na view e para isso faça como abaixo:
ValueExpression ve = expressionFactory.createValueExpression(elContext, "#{bean.campo[" + z + "]}", String.class);

Veja que agora declaramos o ValueExpression, com isso estamos adicionando o que acostumamos fazer somente na view, incluir um parâmetros para capturar o valor que o usuário digitou. Note que é uma expressionFactory criando o valor pegando o contexto e definido a classe que terá o valor na view, neste caso o valor foi uma string, mas poder ser mudado de acordo com sua necessidade. Agora devemos adicionar a ValueExpression para ser incluída no componente inputText
 in.setValueExpression("value", ve);

O nome value dever ser colocado sempre, pois representa a tag value do componente inputText e a variavel ve que é o EL. Para dar o toque final deveremos adicionar os componentes no panel que criamos no inicio como abaixo:
panel.getChildren().add(opl);
            panel.getChildren().add(in);

Com isso adicionamos os componentes dinâmicos dentro do panel.

Então é isso pessoal, qualquer dúvida estou a disposição só comentar aqui ou então enviar um e-mail. Até a próxima!