title: Dynamic Graphic Image
body: <p>I am trying to have dynamic graphic image from database.
  I found a few according questions here in SO but somehow it does not work.</p>
  
  <p>Page: </p>
  
  <pre><code>&lt;p:dataList styleClass="routeDatalist" value="#{searchRoutesBean.foundRoutes}" var="uiRoute"&gt;
      &lt;p:outputLabel value="USERID #{uiRoute.owner.id}"/&gt;
      &lt;h:graphicImage value="#{photoStreamer.streamedContent}" styleClass="userProfileImage"&gt;
      &lt;f:param name="userId" value="#{uiRoute.owner.id}" /&gt;
      &lt;/h:graphicImage&gt;
  &lt;p:/dataList&gt;
  </code></pre>
  
  <p>I get my list of objects from backing bean</p>
  
  <pre><code>    @SessionScoped
      @ManagedBean
      public class SearchRoutesBean{
       private List&lt;UIRoute&gt; foundRoutes;
        ...
      }
  </code></pre>
  
  <p>I created a backing bean which should take the userimage bytearray and create a streamed content</p>
  
  <pre><code> @ManagedBean(name = "photoStreamer")
  @ApplicationScoped
  public class PhotoStreamer implements Serializable {
  
      @Autowired
      UserService userService;
  
      private StreamedContent streamedContent;
  
      public StreamedContent getStreamedContent() {
      ExternalContext externalContext = FacesContext.getCurrentInstance()
          .getExternalContext();
      String userId = externalContext.getRequestParameterMap().get("userId");
  
      if (StringUtils.isNotBlank(userId)) {
  
          User user;
          try {
          user = userService.getUserById(Long.valueOf(userId));
          byte[] image = user.getProfileJpegImage();
          if (image != null &amp;&amp; image.length &gt; 0) {
              return new DefaultStreamedContent(new ByteArrayInputStream(
                  image), "image/jpeg");
          } else {
              BufferedImage bufferedImg = new BufferedImage(250, 350,
                  BufferedImage.TYPE_INT_RGB);
              Graphics2D g2 = bufferedImg.createGraphics();
              g2.drawString("User has no ProfilImage", 50, 175);
              ByteArrayOutputStream os = new ByteArrayOutputStream();
  
              ImageIO.write(bufferedImg, "png", os);
  
              return new DefaultStreamedContent(new ByteArrayInputStream(
                  os.toByteArray()), "image/png");
          }
          } catch (NumberFormatException | UserServiceException | IOException e) {
          throw new IllegalStateException(e);
          }
  
      }
      return null;
  
      }
  }
  </code></pre>
  
  <p>I dont know why but the given parameter userId is always null.</p>
  
  <p>Does someone know what could be the problem?
  BR</p>