diff --git a/server/src/main/java/org/gluu/oxtrust/action/SearchPersonAction.java b/server/src/main/java/org/gluu/oxtrust/action/SearchPersonAction.java index d2108568b..296f8a4d4 100644 --- a/server/src/main/java/org/gluu/oxtrust/action/SearchPersonAction.java +++ b/server/src/main/java/org/gluu/oxtrust/action/SearchPersonAction.java @@ -13,8 +13,6 @@ import javax.faces.application.FacesMessage; import javax.inject.Inject; import javax.inject.Named; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import org.gluu.jsf2.message.FacesMessages; import org.gluu.jsf2.service.ConversationService; @@ -46,36 +44,43 @@ public class SearchPersonAction implements Serializable { @Inject private ConversationService conversationService; - @NotNull - @Size(min = 2, max = 30, message = "Length of search string should be between 2 and 30") private String searchPattern; private String oldSearchPattern; + private boolean firstLaunch = false; + private List personList; @Inject private IPersonService personService; public String start() { + firstLaunch = true; return search(); } public String search() { + if (!firstLaunch && (this.searchPattern.isEmpty() || this.searchPattern.length() < 2)) { + firstLaunch = false; + facesMessages.add(FacesMessage.SEVERITY_ERROR, "Length of search string should be between 2 and 30"); + return OxTrustConstants.RESULT_SUCCESS; + } if (Util.equals(this.oldSearchPattern, this.searchPattern)) { + firstLaunch = false; return OxTrustConstants.RESULT_SUCCESS; } - try { this.personList = personService.searchPersons(this.searchPattern); this.oldSearchPattern = this.searchPattern; - this.searchPattern=""; + this.searchPattern = ""; + firstLaunch = false; } catch (Exception ex) { log.error("Failed to find persons", ex); - + facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to find persons"); conversationService.endConversation(); - + firstLaunch = false; return OxTrustConstants.RESULT_FAILURE; }