Попытка воспроизвести следующую ссылку Загрузить изображение из вне веб-приложения я не могу отображать изображения со следующего URL-адреса http://localhost:8080/images/eventHead1.jpg на странице xhtml.
Один только URL-адрес работает нормально: служба Wildfly обслуживает изображение, расположенное в папке standalone\data\images, без каких-либо проблем непосредственно в браузере. Однако изображение не может быть отображено на странице xhtml из-за следующей ошибки.
Я подозреваю, что Bean неправильно определил параметр "pathString", так как метод getImage возвращает значение null. Ценю вашу помощь.
Используемые версии: Mojarra: 2.3.9; Простые лица: 7.0; Дикая муха: 16
Ошибка:
23:08:42,869 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /Intranet/dashboard.xhtml: javax.servlet.ServletException: Method not found: class com.org.ui.ImageBean.getImage(null)
автономный.xml:
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<location name="/images" handler="ContentDir"/> //added
<http-invoker security-realm="ApplicationRealm"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
<file name="ContentDir" path="${jboss.home.dir}/standalone/data/images" directory-listing="true"/> // added
</handlers>
Бин:
@ManagedBean
@RequestScoped
public class ImageBean {
public StreamedContent getImage() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
return new DefaultStreamedContent();
}
else {
// So, browser is requesting the image. Return a real StreamedContent with the image bytes.
String filename = context.getExternalContext().getRequestParameterMap().get("filename");
String pathString = "http://localhost:8080/images/";
return new DefaultStreamedContent(new FileInputStream(new File(pathString, filename)));
}
}
}
xhtml:
<p:graphicImage value="#{imageBean.image}">
<f:param name="filename" value="#{myevent.imageName}" />
</p:graphicImage>
<img src="/images/filename.ext" />
- person BalusC   schedule 17.02.2020<h:graphicImage value="/images/#{myevent.imageName}">
, но оно не извлекает изображения. - person LEK   schedule 17.02.2020<img src>
, как указано в предыдущем комментарии. - person BalusC   schedule 17.02.2020#{myevent.imageName}
в<img src>
. Спасибо - person LEK   schedule 17.02.2020