I have an auto complete that allows a user to select an item or type text but when save button is clicked, the text typed by user is not saved, this only saves when the user selects an item from the auto complete, I get an exception in the converter showing customerId with "text typed by user" cannot be found and other fields are saved. How do I modify the autocomplete or rate converter to save text typed by user?
xhtml
<h:form id="main"
<div>
<p:outputLabel for="rate" value="Rate" styleClass="font-semibold"/>
<p:autoComplete id="rate" value="#{forexBean.rateType.rateId}" class="w-full" var="rate" itemLabel="#{rate.currency}" itemValue="#{rate}" completeMethod="#{forexBean.autoCompletedRate}" converter="#{rateConverter}"
minQueryLength="3" forceSelection="false" emptyMessage="sorry, no suggestions" moreText="more items available" scrollHeight="250" queryDelay="1400">
<p:ajax event="itemSelect" listener="#{forexBean.selectAutoCompleteRate}" process="@this" update="main:firstNamePanel main:lastNamePanel"/>
</p:autoComplete>
</div>
</h:form>
converter
public class RateConverter{
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
if(value != null && value.trim().length() > 0)
{
ForexService service = context.getApplication().evaluateExpressionGet(context, "#{forexService}", ForexService.class );
RateType rate = new RateType();
try{
return rate = service.getRateByCustomerId(value);
catch(Exception e){
RateType manualEntry = new RateType();
manualEntry.setCurrency(value);
return manualEntry;
}}
return new RateType();}
public String getAsString(FacesContext context, UIComponent component, Object object){
if(Object != null){
return = ((RateType) object).getUniqueCustomerId();
else{
return null;
}
}
}
I also tried setting the value manualEntry.setCurrency(value); typed by user, when I do logging it shows that the value is picked and all other fields are null but value is not saved to the database