1

页:

<p:graphicImage value="#{testController.QR}" />

测试控制器 bean:

private StreamedContent QR;
private ByteArrayOutputStream rawQR;

public StreamedContent getQR() {
    if (rawQR != null) {
        rawQR = QRCode.from("test").to(ImageType.PNG).stream();
        ByteArrayInputStream is = new ByteArrayInputStream(rawQR.toByteArray());
        QR = new DefaultStreamedContent(is, "image/png");
        return QR;
    } else {
        return null;
    }
}

我正在尝试在页面上显示 QR 图像。

使用 SessionScoped 上面的代码可以工作,但是使用 ViewScoped 它会显示一个损坏的图像图标,我需要我的 bean 是 ViewScoped。我在这里想念什么?

二维码参考:http: //viralpatel.net/blogs/create-qr-codes-java-servlet-qr-code-java/

4

0 回答 0