Пример #1
0
  public StreamedContent getImage() {
    FacesContext context = FacesContext.getCurrentInstance();
    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
      // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right
      // URL.
      return new DefaultStreamedContent();
    } else {
      //  String presenteId =
      // context.getExternalContext().getRequestParameterMap().get("presenteID");
      HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
      String presenteId = (String) session.getAttribute("idPresente");
      session.removeAttribute("idPresente");
      System.out.print("\npppppp" + presenteId + "\n");
      presente = dao.buscaId(Integer.parseInt(presenteId), Presente.class);
      System.out.print("\n" + presente.getId() + "\n");
      byte[] b = presente.getImagem();

      if (b != null) {
        InputStream is = new ByteArrayInputStream(b);
        image = new DefaultStreamedContent(is, "image/jpeg", "fileName.jpg");
        return image;
      } else {
        image = null;
      }

      return image;
    }
  }
Пример #2
0
  public StreamedContent getImagenComprobante() {

    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
      // Renderizamos el HTML. Devuelve un stub StreamedContent para generar el URL correcto.
      return new DefaultStreamedContent();
    } else {
      // El browser requiere la imagen. Devuelve el StreamedContent real con los bytes de la imagen.
      String nombreArchivo = context.getExternalContext().getRequestParameterMap().get("archivo");

      System.out.println("Nombre de Archivo >> " + nombreArchivo);

      for (Archivorendicion ar : getListaComprobantes()) {
        if (ar.getNombrearchivo().equals(nombreArchivo)) {
          // BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
          // ByteArrayOutputStream os = new ByteArrayOutputStream();
          // ImageIO.write(bufferedImg, "png", os);
          // imagen = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()),
          // "image/png");
          return new DefaultStreamedContent(new ByteArrayInputStream(ar.getArchivo()));
        }
      }
    }

    return new DefaultStreamedContent();
  }
Пример #3
0
  /**
   * Return the value last set on this <code>FacesContext</code> instance when {@link
   * #setCurrentPhaseId} was called.
   *
   * @throws IllegalStateException if this method is called after this instance has been released
   * @since 2.0
   */
  public PhaseId getCurrentPhaseId() {

    if (defaultFacesContext != null) {
      return defaultFacesContext.getCurrentPhaseId();
    }

    throw new UnsupportedOperationException();
  }
Пример #4
0
  public StreamedContent getImage() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
      return new DefaultStreamedContent();
    } else {
      String id = context.getExternalContext().getRequestParameterMap().get("artistId");
      if (id == null || id.isEmpty()) return new DefaultStreamedContent();
      Artist artist = getServiceProxy().getById(id, new GenericType<Artist>() {});

      return artist.getImageJSF();
    }
  }
  public void valueChangeListener(ValueChangeEvent valueChangeEvent) {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    PhaseId phaseId = facesContext.getCurrentPhaseId();
    logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString());

    String phaseName = phaseId.getName();
    FacesMessage facesMessage =
        new FacesMessage(
            "The valueChangeListener method was called during the "
                + phaseName
                + " phase of the JSF lifecycle.");
    facesContext.addMessage(null, facesMessage);
  }
Пример #6
0
  public StreamedContent getImage() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
      // So, we're rendering the HTML. Return a stub StreamedContent so
      // that it will generate right URL.
      return new DefaultStreamedContent();
    } else {
      // So, browser is requesting the image. Return a real
      // StreamedContent with the image bytes.
      String dishId = context.getExternalContext().getRequestParameterMap().get("id");
      Dish dish = dishFacade.findById(Integer.valueOf(dishId));
      return new DefaultStreamedContent(new ByteArrayInputStream(dish.getImages()));
    }
  }
Пример #7
0
  public StreamedContent getImage() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
      // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right
      // URL.
      return new DefaultStreamedContent();
    } else {
      // So, browser is requesting the image. Return a real StreamedContent with the image bytes.
      Integer recipeId =
          Integer.parseInt(context.getExternalContext().getRequestParameterMap().get("recipeId"));
      Recipe recipe = service.getById(recipeId);

      byte[] photo = recipe.getPhoto();
      if (photo == null) {
        return null;
      }

      return new DefaultStreamedContent(new ByteArrayInputStream(photo));
    }
  }
Пример #8
0
 /**
  * While setting up PartialViewContextImpl the RI's FacesContextImpl is passed in, but while
  * processing phases also FacesContextWrapper must be supported. Therefore ctx is updated until
  * processing phases has started. Released FacesContext is updated too.
  */
 private void updateFacesContext() {
   if (!processingPhases || ctx.isReleased()) {
     ctx = FacesContext.getCurrentInstance();
     processingPhases = ctx.getCurrentPhaseId() != null;
   }
 }