使用“o:graphicImage”的示例:“下面的渲染字节 [] 属性在
添加全脸:
implementation("org.omnifaces:omnifaces:4.0.1")
仅在战争中部署:
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>
爪哇:
@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()]);
}
}
终端“信息”:
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' 属性必须引用 @GraphicImageBean 或 @ApplicationScoped bean。无法在 bean 类上找到正确的注释”
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'.
技术支持:
(2)
@BalusC 您的评论“您的 EAR 的 JAR 部分应该将 OmniFaces 声明为提供的依赖项而不是运行时依赖项”。我无法理解“依赖”参考。
查看了您对“如何在 EAR 中正确使用 OmniFaces”的“堆栈溢出”响应:
我有:
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
总是与:
<o:graphicImage value="#{graphicImagesController.getContent(id)}" lastModified="#{startup.time}" />
错误:
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)
演示:组件 - graphicImage
返回尝试“下面的呈现字节 [] 属性,在
<h3>The below one renders byte[] property taking a Long argument as resource in <code><ui:repeat></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");
}
}
野蝇 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
使用:
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")
没有错误但没有显示?