I want to build p: autocomplete to search for different objects from objects. As a client, the article ....
The search works well and objects appear. But still the converter does not work.
Here is my code:
<p:autoComplete id="searchStartpage" size="35" maxlength="200" queryDelay="0" maxResults="10" minQueryLength="1" value="#{searchGeneralRequestController.selectedObject}" completeMethod="#{searchGeneralRequestController.completeObject}" var="o" itemLabel="#{object.id}" itemValue="#{object}" converter="objectForSearchConverter" forceSelection="false" itemtipMyPosition="left center" cache="false" itemtipAtPosition="right center"> <p:ajax event="itemSelect" listener="#{searchGeneralRequestController.handleSelect}" /> <p:column rendered="#{o.getClass().getSimpleName() == 'Mandatory'}">
And here is my converter:
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) { if (submittedValue.trim().equals("")) { return null; } else { try { // searchValue = submittedValue; int number = Integer.parseInt(submittedValue); for (Object p : objectList) { if (p instanceof Article) { Article article = (Article) p; if (article.getId() == number) { return p; } } if (p instanceof Customer) { Customer customer = (Customer) p; if (customer.getId() == number) { return p; } } if (p instanceof User) { User user = (User) p; if (user.getId() == number) { return p; } } if (p instanceof Mandatory) { Mandatory mandatory = (Mandatory) p; if (mandatory.getId() == number) { return p; } } } } catch (NumberFormatException exception) { throw new ConverterException(new FacesMessage( FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player")); } } return null; } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { if (value == null || value.equals("")) { return ""; } else { Long id = (value instanceof Mandatory) ? ((Mandatory) value) .getId() : null; return (id != null) ? String.valueOf(id) : null; } }
All my entities have a hash and string method. Object is always null
Can someone help please
source share