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

Nenhum comentário: