This content has been marked as final.
Show 3 replies
-
1. Re: EntityConverter - when and how?
norman.richards Mar 31, 2007 9:38 PM (in response to irvega)The entity converter is a JSF converter for entities. If you don't understand what a JSF converter is, you should take a look at a good JSF book.
The main use case I've found for entity converter is to provide a string-object mapping for use in menus and dropdowns. The DVD store uses it in the search box to allow the user to select a search category. -
2. Re: EntityConverter - when and how?
irvega Mar 31, 2007 10:38 PM (in response to irvega)OK, so the catbean.categories in
<h:selectOneMenu value="#{search.category}" converter="#{catbean.converter}"> <f:selectItem itemLabel="Any" itemValue="#{catbean.nullCategory}" /> <f:selectItems value="#{catbean.categories}" /> </h:selectOneMenu>
returns the map populated in the CategotyBean at instantiation.
When the converter is called into action, it takes the key (the selected Category's name), now in the appropriate context, and looks up the actual Category object (in the same map) to get that Category's id for use in the query.
Is that a better way to achieve this effect than the use of something like an entityQuery for retrieving the Categorys (categoriesQuery) with the following in the components.xml ?<h:selectOneListbox <h:selectOneMenu value="#{search.category}" <s:selectItems value="#{categoriesQuery.resultList}" var="category" label="#{category.name}" /> </h:selectOneMenu>
Would a converter be needed in this case? What are the pros and cons of each approach (assuming my suggestion would even work - haven't tried it yet)? -
3. Re: EntityConverter - when and how?
norman.richards Mar 31, 2007 11:39 PM (in response to irvega)No, it would look like this:
<h:selectOneMenu value="#{search.category}"> <s:convertEntity /> <s:selectItems value="#{allCategories.resultList}" var="category" label="#{category.name}" noSelectionLabel="ANY" /> </h:selectOneMenu>