rich:autocomplete or a new component?
clerum Aug 16, 2011 11:14 AMOften in my application I have edit pages for a specific enitity and I need to edit the non-collection side of a ManyToOne association. My prefered way of doing this is to use a autocomplete component backed by a search method using hibernate search.
In RF 3 I accomplished this with a mess like this.
<s:div id="siteDiv"> <a:region> <s:decorate template="/layout/view.xhtml" rendered="#{ticket.site != null}"> <ui:define name="label">Site:</ui:define> <h:outputText value="#{ticket.site.toString()}" converter="stringTrim30" /> <h:outputText value=" :: "/> <span class="actionLinks"> <a:commandLink value="Clear" action="#{ticketUtil.updateSite(null)}" rendered="#{ticketTools.allowSiteEdit(ticket)}" reRender="associationsDiv" /> </span> </s:decorate> <s:decorate template="/layout/edit.xhtml" rendered="#{ticket.site == null}"> <ui:define name="label">Site:</ui:define> <h:inputText id="site" size="50" required="false" tabindex="5"/> <rich:suggestionbox for="site" suggestionAction="#{siteLists.searchSites}" var="_site" minChars="2" id="suggestion" width="500" nothingLabel="No Sites Found"> <h:column> <h:outputText value="#{siteTools.getFullName(_site)}" /> </h:column> <a:support ajaxSingle="true" action="#{ticketUtil.updateSite(_site)}" event="onselect" reRender="associationsDiv"/> </rich:suggestionbox> </s:decorate> </a:region> </s:div>
As I'm going through RF4 I'm not quite sure how to accomplish the same thing. The requirements would be:
1. POJO support. The backing value should be an object #{ticket.site} but there should be a label #{site.displayName}
2. Force selection. If the user types in "Monkey" and that doesn't match anything to bring up a result in the suggest drop down then "Monkey" should be cleared from the input on blur. Also if something did match and was selected then adding new characters to the input should null the value and execute the search method for more.
3. Read only. In conjuntion with 2 I would probably want to set the component as read only after a value was selected so that the user cannot type in the field anymore readOnly="#{ticket.site != null}". I would then use an a:commandbutton or similar to set the ticket.site = null if I wanted to edit it again.
Primefaces does this in 3.0
<p:autoComplete id="entity" readonly="#{_contact.appEntity != null}" forceSelection="true" value="#{_contact.appEntity}" var="_ae" itemLabel="#{_ae.name}" itemValue="#{_ae}" completeMethod="#{entitySearch.appEntity}" converter="appEntityConverter" />
Is this possible in RF4? If something is missing can it be added to the existing rich:autocomplete?