QRCode dynamically generates QR codes with options such as rendering mode, color, size and more. Based on jQuery.qrcode by Lars Jung.
Play with the option values and click update to generate the QR code.
<div class="card">
<h5>Simple Usage</h5>
<p>Play with the option values and click <i>update</i> to generate the QR code.</p>
<h:form id="formBasicUsage">
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Render method: "/>
<p:selectOneButton value="#{qrCodeController.renderMethod}">
<f:selectItem itemLabel="canvas" itemValue="canvas"/>
<f:selectItem itemLabel="image" itemValue="img"/>
<f:selectItem itemLabel="div" itemValue="div"/>
</p:selectOneButton>
<h:outputText value="Render mode:"/>
<p:selectOneButton value="#{qrCodeController.mode}">
<f:selectItem itemLabel="normal" itemValue="0"/>
<f:selectItem itemLabel="label strip" itemValue="1"/>
<f:selectItem itemLabel="label box" itemValue="2"/>
<f:selectItem itemLabel="image strip" itemValue="3"/>
<f:selectItem itemLabel="image box" itemValue="4"/>
</p:selectOneButton>
<h:outputText value="Size:"/>
<h:panelGrid columns="1">
<h:inputHidden id="txt2" value="#{qrCodeController.size}"/>
<p:slider minValue="50" maxValue="500" for="txt2" style="width:200px"/>
</h:panelGrid>
<h:outputText value="Fill color:"/>
<p:colorPicker value="#{qrCodeController.fillColor}"/>
<p:commandButton value="update" update="qrCodeElem"/>
</h:panelGrid>
<p:divider/>
<pe:qrCode id="qrCodeElem"
renderMethod="#{qrCodeController.renderMethod}"
renderMode="#{qrCodeController.mode}"
text="#{qrCodeController.text}"
label="#{qrCodeController.label}"
size="#{qrCodeController.size}"
fillColor="#{qrCodeController.fillColor}"
fontName="Ubuntu"
fontColor="#01A9DB"
ecLevel="H"
radius="0.5"/>
</h:form>
</div>
package org.primefaces.extensions.showcase.controller;
import java.io.Serial;
import java.io.Serializable;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
/**
* InputNumberController
*
* @author Mauricio Fenoglio / last modified by $Author$
* @version $Revision$
* @since 0.3
*/
@Named("qrCodeController")
@ViewScoped
public class QRCodeController implements Serializable {
@Serial
private static final long serialVersionUID = 20120316L;
private String renderMethod;
private String text;
private String label;
private int mode;
private int size;
private String fillColor;
public QRCodeController() {
renderMethod = "canvas";
text = "http://primefaces-extensions.github.io/";
label = "PF-Extensions";
mode = 2;
fillColor = "7d767d";
size = 200;
}
public String getRenderMethod() {
return renderMethod;
}
public void setRenderMethod(final String renderMethod) {
this.renderMethod = renderMethod;
}
public String getText() {
return text;
}
public void setText(final String text) {
this.text = text;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
public int getMode() {
return mode;
}
public void setMode(final int mode) {
this.mode = mode;
}
public String getFillColor() {
return fillColor;
}
public void setFillColor(final String fillColor) {
this.fillColor = fillColor;
}
public int getSize() {
return size;
}
public void setSize(final int size) {
this.size = size;
}
}