Hello
my question:
for example i have a h:selectOneMenu, witch present the streets in the any (chose before) town
this selection in xhtml page looks like
<h:selectOneMenu id="town_4" value="#{locationAddAction.street}" immediate="true">
<f:selectItems value="#{locationAddAction.streetLookup}" />
<fmedia:streetConverter town="#{locationAddAction.town}" />
</h:selectOneMenu>
in my project i need to convert a string into Street object stored in DB
but there are can be many streets with the same names, but difference in town reference
so i need the town attribute in converter
my converter class extends javax.faces.convert.Converter
public class StreetConverter implements Converter {
private LocationService locationService = new LocationService();
private Town town;
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
Town town = locationService.getStreetByNameMatch(town,arg2)
return town;
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
if (arg2 instanceof Street)
return ((Street) arg2).getName();
return null;
}
public Town getTown() {
return town;
}
public void setTown(Town town) {
this.town = town;
}
}
i registered my converter with parameter in faces-config.xml
<converter>
<converter-id>streetConverter</converter-id>
<converter-class>package.StreetConverter</converter-class>
<attribute>
<attribute-name>town</attribute-name>
<attribute-class>package.Town</attribute-class>
</attribute>
</converter>
and create my facelet tag
<tag>
<tag-name>streetConverter</tag-name>
<converter>
<converter-id>streetConverter</converter-id>
</converter>
</tag>
PROBLEM:
any request to my converter (StreetConverter, <fmedia:streetConverter>) set the new creation of my Converter
but the initialization of "town" field happend only once in creation page (when i'm requesting whole jsf page) and any request to converter is erasing my town parameter, becouse it has been init in another converter object.
how can i initialize town attribute in all requests to converter ?
sorry my horrible english
thanks =)