I implemented with success the converter for h:selectOneMenu
used by one bean but I want to use the same converter from a different bean instead to create the same converter another time.
currently I have:
Converter
@FacesConverter(value = "csiConverter")
public class CsiConverter implements Converter {
@Override
public Object getAsObject(FacesContext ctx, UIComponent uiComponent, String dcId) {
ValueExpression vex =
ctx.getApplication().getExpressionFactory()
.createValueExpression(ctx.getELContext(),
"#{cfgbean}", CfgDbBean.class);
...
}
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
return ((Csi) o).getCsi();
}
and the xhtml
<div class="form-group">
<label>CSI</label>
<h:selectOneMenu id="csi" styleClass="form-control" value="#{cfgbean.csi}" converter="csiConverter">
<f:selectItems var="csival" itemLabel="#{csival.csi} - #{csival.name}" itemValue="${csival}" value="#{cfgbean.csilist}" />
</h:selectOneMenu>
</div>
this is working all fine.
Now I would like to create in a different xhtml the same selectOneMenu
contacting a different bean for the same purpose to show the same content.
Problem is that inside the Converter class is cabled the bean reference and bean class.(createValueExpression(ctx.getELContext(), "#{cfgbean}", CfgDbBean.class);
)
How can avoid to cable that references and have a generic csiConverter
for all Beans?
thanks