JSF Converter <p:selectonemenu [duplicate] - jsf

This question already has answers here:
How to populate options of h:selectOneMenu from database?
(5 answers)
Closed 6 years ago.
I can't create converter class in jsf for
<p:column>
<h:outputText value="#{t.idmehsul.adi}" />
</p:column>
</p:selectOneMenu>

Step by step create a converter in jsf:
Create a converter class by implementing javax.faces.convert.Converter interface.
Implement getAsObject() and getAsString() methods of above interface.
Use Annotation #FacesConvertor to assign a unique id to the custom convertor.
You can refer at here to understand more how to create a converter in JSF.

Related

How I can use a converter in a JSF tag selectOneMenu? [duplicate]

This question already has answers here:
How to populate options of h:selectOneMenu from database?
(5 answers)
Closed 4 years ago.
The following example works in my interface:
<h:outputText value="#{diplome.pays}">
<gn:converter origine="#{config.origManSirhen}"
nomenclature="#{config.codePays}"
propriete="libelleImpression" />
</h:outputText>
However, when I try to use the same converter does not work when the element is a selectOneMenu
<p:selectOneMenu id="pays">
<f:selectItem
itemValue="#{InformationsPersonnellesModele.adressePrincipale.pays}"
itemLabel="#{InformationsPersonnellesModele.adressePrincipale.pays}" />
<gn:converter origine="#{config.origManSirhen}"
nomenclature="#{config.codePays}" propriete="libelleImpression" />
</p:selectOneMenu>
I have tried to use the attribute converter into the selectOneMenu tag, but it does not work as I expect because I need to use as well the parameter nomenclature and propiete.
I found a possible solution:
The item selected by default must be the value of the selectOneMenu tag.
And the list of items and the converter are directly assigned to the value of the selectItems tag.
<p:selectOneMenu id="pays"
value="#{InformationsPersonnellesModele.adressePrincipale.pays}">
<f:selectItems
value="#{gnl:listeTri(config.origManSirhen, config.codePays,'libelleImpression')}" />
</p:selectOneMenu>

PrimeFaces dataTable method called many times [duplicate]

This question already has answers here:
Defining and reusing an EL variable in JSF page
(2 answers)
Closed 6 years ago.
I have a datatable with a column:
<p:dataTable value="#{cc.attrs.bean.model}"
...
<p:column style="width:#{bean.getWidth('colDate', 55)}px;"
It seems that the bean.getWidth method is called for every row in the table. Thus, when having 100 rows, the method is called a hundred times. I expected the method to be called only once.
Am I wrong?
No, it's right.
You can cache the value into your bean or use JSTL
<c:set var="width" value="#{bean.getWidth('colDate', 55)}" />
<p:dataTable value="#{cc.attrs.bean.model}"
...
<p:column style="width:#{width}px;"
You can find more infos here https://stackoverflow.com/tags/jstl/info.
Don't forget the namespace .
you can save result of getWidth in managed bean attribute then use this in column style

How can I add JSF code to xhtml in the attribute id? [duplicate]

This question already has answers here:
How to dynamically generate id in dataTable using ui:repeat tag
(4 answers)
How to use EL with <ui:repeat var> in id attribute of a JSF component
(1 answer)
Closed 6 years ago.
I am working with JSF 2.2 and I would like use JSF variables in the id attribute for to send individuals petitions for each list's element.
For example:
<ui:repeat value="#{bean.numbers}" var="number">
<h:inputText id="text#{number}"/>
</ui:repeat>
Thank you

Is it possible to use EL in ui:repeat? [duplicate]

This question already has an answer here:
How to use EL with <ui:repeat var> in id attribute of a JSF component
(1 answer)
Closed 7 years ago.
Mojarra 2.1.29
I've read that usually it's not necessary to use EL to generate id-attribute dynamically. I also know that the id-attribute resolved at view-building phase. But in our projects we have to write some Selenium tests which are goign to use some html-attribute in the generated markup. So, I decided to specify the id-attribute dynamically. How can I do that for the following <ui:repeat>:
#ManagedBean
#SessionScoped
public class Bean{
private List<Integer> values;
//GET, SET
public Bean(){
values = Arrays.asList(1,2,5,7,8,9);
}
}
<ui:repeat value="#{bean.values}" var="value">
<h:outputText id="#{value}" /> <!-- not legal, resolved to null -->
</ui:repeat>
Maybe I should specify another attribute fo Selenium instead?
If you provide a fixed id like the following.
<ui:repeat value="#{bean.values}" var="value">
<h:outputText id="elementId" />
</ui:repeat>
The element you need will have ids generated as,
parentId:0:elementId
parentId:1:elementId
parentId:2:elementId
and so on.

Conversion Error setting value '1' for 'null Converter' [duplicate]

This question already has answers here:
How to populate options of h:selectOneMenu from database?
(5 answers)
Closed 7 years ago.
When I click submit button in a jsf page I get the above error.
html:
<h:selectOneMenu id="ddlCountryCode" value="#{jsfFills.countries}">
<f:selectItems value="#{jsfFills.countries}" var="c"
itemLabel="#{c.CName}" itemValue="#{c.CCode}" />
</h:selectOneMenu>
The "value" attribute should point to a variable where you want to store the selected value of the component, not the list of choices.
In the example above, jsfFills.countries is used as both the list of options AND the value of the component, and that could be causing the issue. We'd want to create a variable in a bean somewhere and use that instead.
<h:selectOneMenu id="ddlCountryCode" value="#{jsfFills.selectedCountry}">
<f:selectItems value="#{jsfFills.countries}" var="c"
itemLabel="#{c.CName}" itemValue="#{c.CCode}" />
</h:selectOneMenu>

Resources