0

Using the example of 'o:graphicImage': "The below one renders byte[] property taking a Long argument as resource in <ui:repeat> loop": https://showcase.omnifaces.org/components/graphicImage

Adding Omnifaces:

implementation("org.omnifaces:omnifaces:4.0.1")

Deployed only in WAR:

WEB-INF/lib/omnifaces-4.0.1.jar

XHTML:

<ui:repeat value="#{graphicImagesController.ids}" var="id">
    <o:graphicImage value="#{graphicImagesController.getContent(id)}" lastModified="#{startup.time}"/>
</ui:repeat>

Java:

@Named("graphicImagesController")
@GraphicImageBean
public class GraphicImagesController {

    private static final Logger LOGGER = LoggerFactory.getLogger(GraphicImagesController.class);

    private static final Map<Long, String> IMAGES = Collections.unmodifiableMap(new TreeMap<Long, String>() {
        private static final long serialVersionUID = 1L;

        {
            put(1L, "3862a9b4c41cacd3465d0edb80c2072d");
        }
    });

    public byte[] getContent(Long id) throws IOException {
        return Utils.toByteArray(Faces.getResourceAsStream("/Users/NOTiFY/IdeaProjects/NOTiFYmoto/images/moto/Laverda/1977/1000/Jota/" + IMAGES.get(id) + ".jpg"));
    }

    public Long[] getIds() {
        LOGGER.info(">>>>> GraphicImagesController getIds IMAGES = {}", IMAGES);
        LOGGER.info(">>>>> GraphicImagesController getIds IMAGES size = {}", IMAGES.size());

        return IMAGES.keySet().toArray(new Long[IMAGES.size()]);
    }
}

Terminal 'INFO':

INFO  [com.notifymoto.controller.GraphicImagesController] (default task-1) >>>>> GraphicImagesController getIds IMAGES = {1=3862a9b4c41cacd3465d0edb80c2072d}
INFO  [com.notifymoto.controller.GraphicImagesController] (default task-1) >>>>> GraphicImagesController getIds IMAGES size = 1

Terminal 'SEVERE': " o:graphicImage 'value' attribute must refer a @GraphicImageBean or @ApplicationScoped bean. Cannot find the right annotation on bean class"

SEVERE [jakarta.enterprise.resource.webcontainer.faces.application] (default task-1) Error Rendering View[/index.xhtml]: java.lang.IllegalArgumentException: o:graphicImage 'value' attribute must refer a @GraphicImageBean or @ApplicationScoped bean. Cannot find the right annotation on bean class 'class com.notifymoto.controller.GraphicImagesController'.

Powered by:

  • Mojarra 4.0.0.SP01
  • OmniFaces 4.0.1
  • PrimeFaces 12.0.3
  • WildFly Preview 27.0.1.Final
  • Jakarta EE 10.0.0
  • EAR = JAR + WAR (Gradle)

(2)

@BalusC Your comment "the JAR part of your EAR should be declaring OmniFaces as a provided dependency instead of as a runtime dependency". I can't understand the 'dependency' reference.

Looked at your 'stack overflow' response on "How to correctly use OmniFaces in an EAR":

How to correctly use OmniFaces in an EAR

I have:

libs/NOTiFYmoto.ear:

lib/
lib/gson-2.10.jar
lib/httpclient-4.5.13.jar
lib/httpcore-4.4.14.jar
lib/kotlin-stdlib-1.8.10.jar
lib/morphia-core-2.3.0.jar
lib/mongodb-driver-core-4.8.2.jar
lib/mongodb-driver-sync-4.8.2.jar
lib/bson-4.8.2.jar
lib/byte-buddy-1.12.17.jar
lib/classgraph-4.8.153.jar
NOTiFYmotoWAR.war
NOTiFYmotoJAR.jar
META-INF/application.xml

libs/NOTiFYmotoJAR.jar:

META-INF/
META-INF/MANIFEST.MF
META-INF/beans.xml
META-INF/persistence.xml

... .class

com/notifymoto/controller/GraphicImagesController.class
com/notifymoto/controller/GraphicImagesController$1.class

libs/NOTiFYmotoWAR.war:

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/lib/

... .jar

WEB-INF/lib/omnifaces-4.0.1.jar

Always with:

<o:graphicImage value="#{graphicImagesController.getContent(id)}" lastModified="#{startup.time}" />

Error:

SEVERE [jakarta.enterprise.resource.webcontainer.faces.application] (default task-1) Error Rendering View[/index.xhtml]: java.lang.IllegalArgumentException: o:graphicImage 'value' attribute must refer a @GraphicImageBean or @ApplicationScoped bean. Cannot find the right annotation on bean class 'class com.notifymoto.controller.GraphicImagesController'.

(3)

Back trying to run "demo: components - graphicImage" with "The below one renders byte[] property taking a Long argument as resource in <ui:repeat> loop":

<h3>The below one renders byte[] property taking a Long argument as resource in <code>&lt;ui:repeat&gt;</code> loop</h3>
<p>
    <ui:repeat value="#{notifyImages.ids}" var="id">
        <o:graphicImage value="#{notifyImages.getContent(id)}" lastModified="#{startup.time}" />
    </ui:repeat>
</p>

'GraphicImageBean':

@Named("notifyImages")
@GraphicImageBean
public class NotifyImages {

    private static final Logger LOGGER = LoggerFactory.getLogger(notifyImages.class);

    private static final Map<Long, String> IMAGES = Collections.unmodifiableMap(new TreeMap<Long, String>() {
        private static final long serialVersionUID = 1L;

        {
            put(1L, "black");
            put(2L, "blue");
            put(3L, "yellow");
            put(4L, "gray");
            put(5L, "red");
            put(6L, "green");
        }
    });

    public InputStream getLogo() {
        // Note: this is a dummy example. In reality, you should be able to take e.g. a Long argument as ID and then
        // return the desired byte[] content from some service class by given ID.

        return Faces.getResourceAsStream("/resourc" +
            "es/layout/img/OmniFaces-logo-90x90-black.png");
    }

    public byte[] getContent(Long id) throws IOException {
        // Note: this is a dummy example. In reality, you should be able to return the desired byte[] content from some
        // service class by given ID.
        
        return Utils.toByteArray(Faces.getResourceAsStream("/resources/layout/img/OmniFaces-logo-90x90-" + IMAGES.get(id) + ".png"));
    }

    public Long[] getIds() {
        // Note: this is just a dummy example. In reality, you should be able to obtain them from another request/view
        // scoped bean as ID of an entity representing the image.

        return IMAGES.keySet().toArray(new Long[IMAGES.size()]);
    }

    public InputStream getSvgLogo() {
        // Note: this is a dummy example. In reality, you should be able to take e.g. a Long argument as ID and then
        // return the desired byte[] content from some service class by given ID.

        return Faces.getResourceAsStream("/resources/layout/img/OmniFaces-logo.svg");
    }
}

WildFly 27.0.1:

INFO  [org.omnifaces.ApplicationInitializer] (ServerService Thread Pool -- 92) Using OmniFaces version 4.1
INFO  [io.undertow.websockets.jsr] (ServerService Thread Pool -- 92) UT026005: Adding programmatic server endpoint class org.omnifaces.cdi.push.SocketEndpoint for path /omnifaces.push/{channel}
INFO  [jakarta.enterprise.resource.webcontainer.faces.config] (ServerService Thread Pool -- 92) Initializing Mojarra 4.0.0.SP01 for context '/NOTiFYmoto'

/Users/NOTiFY/IdeaProjects/NOTiFYmoto/build/libs/NOTiFYmotoWAR.war

META-INF/
WEB-INF/lib/omnifaces-4.1.jar
resources/layout/img/OmniFaces-icon-512x512.png
resources/layout/img/OmniFaces-logo-90x90-white.png
resources/layout/img/OmniFaces-logo-370x370-black.png
resources/layout/img/OmniFaces-logo-90x90-red.png
resources/layout/img/OmniFaces-logo-90x90-blue.png
resources/layout/img/OmniFaces-logo-90x90-gray.png
resources/layout/img/OmniFaces-logo-90x90-yellow.png
resources/layout/img/OmniFaces-logo-90x90-green.png
resources/layout/img/OmniFaces-logo-90x90-black.png
resources/layout/img/OmniFaces-icon-192x192.png
resources/layout/img/OmniFaces-logo-370x370-white.png
resources/layout/img/OmniFaces-logo.svg

Using:

WildFly Preview 27.0.1.Final (WildFly Core 19.0.1.Final)
openjdk version "19.0.2" 2023-01-17
implementation("org.omnifaces:omnifaces:4.1")

No errors but nothing shown?

NOTiFY
  • 1,255
  • 1
  • 20
  • 36
  • mvn clean package -Pnon-ee,mojarra-4.0 runs on https://localhost:8443/components/graphicImage works on WildFly 27.0.1.Final. Will look at my gradle etc. – NOTiFY Feb 02 '23 at 15:18

0 Answers0