JSF 2.0 converter does not work from a separate jar file

I have a custom converter for selecting a country in the SelectOneMenu component:

File: address.jar

@FacesConverter(value="CountryConverter", forClass=Country.class)
public class CountryConverter implements Converter {

private CountryBean countryBean = CountryBean.getCountryService();

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    return countryBean.find(value);
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value != null)
        return ((Country)value).getcc_fips();
    else
        return null;
}    

And this is the xhtml text:

File: project root

  <h:selectOneMenu id="country" value="#{cc.attrs.addrEntity.country}">
     <f:selectItem itemLabel="Please select one..." 
             noSelectionOption="true" />
     <f:selectItems value="#{cc.attrs.addrBean.countries}"
                    var="model"
                    itemLabel="#{model.name}"
                    itemValue="#{model}"
                    noSelectionValue="&#8220;no selection&#8221;"/>
     <f:converter ConverterId="CountryConverter"/>        
 </h:selectOneMenu>

I have a converter in the file " address.jar ", and when I try to open the page for writing the address, then it replies: "Expression error: an object named MyCustomCoverter was not found." . Even when I copy the converter to the project where the xhtml files are located, it works fine. What can I do to solve this problem?

Why does this not work from a separate jar file?

Thank.

+5
source share
1 answer

JSF 2.0- /META-INF/faces-config.xml JAR , JSF JAR JSF.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
</faces-config>

JSF JAR , , @FacesConverter .

+15

All Articles