Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Parametrized JSF Converter

843844Jul 30 2009 — edited Jul 30 2009
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 =)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2009
Added on Jul 30 2009
2 comments
1,030 views