Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Capturing images with photoCam


Taking images with the attached camera and sending them to the JSF backend data model is supported by photoCam.

How to do it…

A simple definition for capturing an image with the photoCam would be as follows:

<p:photoCam widgetVar="pc" listener="#{photoCamBean.onCapture}"
  update="capturedImage"/>

<p:graphicImage id="capturedImage" 
  value="#{photoCamBean.capturedImage}" cache="false"/>

<p:commandButton type="button" value="Capture"
  onclick="PF('pc').capture()"/>

How it works…

The captured image is triggered via the client-side JavaScript method, capture. The button declared in the preceding sample invokes the capture method via the widget variable defined for the photoCam component. A method expression, which will be invoked when an image is captured, is bound to the attribute. This method will handle the image captured on the server side. A sample definition for the method is as follows:

StreamedContent capturedImage;

public void onCapture...