Ejemplo n.º 1
0
  private Predicate[] getSearchPredicates(Root<Author> root) {

    CriteriaBuilder builder = em.getCriteriaBuilder();
    List<Predicate> predicatesList = new ArrayList<>();

    String firstname = example.getFirstname();
    if (firstname != null && !"".equals(firstname)) {
      predicatesList.add(
          builder.like(
              builder.lower(root.<String>get("firstname")), '%' + firstname.toLowerCase() + '%'));
    }
    String surname = example.getSurname();
    if (surname != null && !"".equals(surname)) {
      predicatesList.add(
          builder.like(
              builder.lower(root.<String>get("surname")), '%' + surname.toLowerCase() + '%'));
    }
    String bio = example.getBio();
    if (bio != null && !"".equals(bio)) {
      predicatesList.add(
          builder.like(builder.lower(root.<String>get("bio")), '%' + bio.toLowerCase() + '%'));
    }
    String twitter = example.getTwitter();
    if (twitter != null && !"".equals(twitter)) {
      predicatesList.add(
          builder.like(
              builder.lower(root.<String>get("twitter")), '%' + twitter.toLowerCase() + '%'));
    }

    return predicatesList.toArray(new Predicate[predicatesList.size()]);
  }
Ejemplo n.º 2
0
  // Support updating and deleting Book entities
  public String update() {
    conversation.end();

    try {
      if (id == null) {
        target.request().post(Entity.entity(author, MediaType.APPLICATION_XML));
        return "search?faces-redirect=true";
      } else {
        target.request().put(Entity.entity(author, MediaType.APPLICATION_XML));
        return "view?faces-redirect=true&id=" + author.getId();
      }
    } catch (Exception e) {
      FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
      return null;
    }
  }