Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeFaces Barcode does not work?

I am trying to get the Barcode from the PrimeFaces Showcase running, but when I place the XHTML code and let it run in my local Wildfly 8, I just get total rubbish. The numbers of every barcode are too big and the QR code does not work at all.

I believe I might have a missing Maven dependency, but I am having trouble to find the necessary one.

Following the documentation, I think I have to integrate the dependency for barcode4j-light in the version 2.1, but I can't find this version on Maven.

How would I have to integrate this? I'd appreciate every help! Thanks in advance!

My Barcode.xhtml:

<!DOCTYPE html>
<html   xmlns="http://www.w3c.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head/>
    <h:body>
        <p:panelGrid columns="2">
            <h:outputText value="Interleaved 2 of 5" />
            <p:barcode value="0123456789" type="int2of5" />

            <h:outputText value="Codabar" />
            <p:barcode value="0123456789" type="codabar"/>

            <h:outputText value="Code39" />
            <p:barcode value="0123456789" type="code39" />

            <h:outputText value="Code128" />
            <p:barcode value="0123456789" type="code128"/>

            <h:outputText value="EAN-8" />
            <p:barcode value="20123451" type="ean8"/>

            <h:outputText value="EAN-13" />
            <p:barcode value="0123456789012" type="ean13"/>

            <h:outputText value="UPC-A (PNG)" />
            <p:barcode value="01234567895" type="upca" format="png"/>

            <h:outputText value="UPC-E (Vertical)" />
            <p:barcode value="01234133" type="upce" orientation="90"/>

            <h:outputText value="PDF417" />
            <p:barcode value="0123456789" type="pdf417"/>

            <h:outputText value="DataMatrix" />
            <p:barcode value="0123456789" type="datamatrix"/>

            <h:outputText value="Postnet" />
            <p:barcode value="0123456789" type="postnet"/>

            <h:outputText value="QR" />
            <p:barcode value="0123456789" type="qr"/>
        </p:panelGrid>
    </h:body>
</html>

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.glasses</groupId>
    <artifactId>primeWork</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>primeWork</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
like image 720
Socrates Avatar asked Sep 12 '26 11:09

Socrates


2 Answers

So barcode4j-light-2.1 isn't available in the Maven Repository. We need to download it from the SourceForge. Once you download it and unzip it, go the build dir. The barcode4j-light jar will be there.

To install it to your local Maven repo, follow these instructions. Basically, from the command line (from the build dir and assuming you have Maven installed) :

C:\...build>mvn install:install-file -Dfile=barcode4j-light.jar 
                                     -DgroupId=net.sf.barcode4j
                                     -DartifactId=barcode4j-light 
                                     -Dversion=2.1 
                                     -Dpackaging=jar

That command should be all on one line and not line separated as you see here. Then you can just add the dependency to your project

<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j-light</artifactId>
    <version>2.1</version>
</dependency>

You will also need this one

<dependency>
    <groupId>net.glxn</groupId>
    <artifactId>qrgen</artifactId>  <!-- QR code support -->
    <version>1.4</version>
</dependency>

Not step by step like this, but this is described in the Prime Faces User Guide. It worked for me, once I followed the above steps.

like image 58
Paul Samsotha Avatar answered Sep 14 '26 14:09

Paul Samsotha


I also have added to my pom.xml:

<repositories>
    <repository>
        <url>http://repository.primefaces.org/</url>
        <id>PrimeFaces-maven-lib</id>
        <layout>default</layout>
        <name>Repository for library PrimeFaces-maven-lib</name>
    </repository>
</repositories>

Who resolve the dependencie problem in NB8 Maven Web Projects.

like image 27
Enrique San Martín Avatar answered Sep 14 '26 13:09

Enrique San Martín