我有这个结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
Run Code Online (Sandbox Code Playgroud)
top.xhtml是一个组件,即在使用index.xthml与about_us.xhtml太.
top.xhtml
<ul>
<li><a href="index.xhtml">Home</a></li>
<li><a href="company/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,当当前页面是index.xhtml组件正确生成URL时,但当当前页面时about_us.xhtml,它会生成错误的URL.我不能使用相对路径,因为它也会生成错误的URL.我认为这是因为组件基于*.xhtml页面的当前路径.
我能找到的唯一解决方案是:
<ul>
<li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
<li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
但我认为根本不是"优雅".有任何想法吗?
我想显示的保存在数据库中的图像字节StreamedContent中<p:graphicImage>,如下所示:
<p:graphicImage value="#{item.imageF}" width="50" id="grpImage" height="80"/>
Run Code Online (Sandbox Code Playgroud)
private StreamedContent content; // getter and setter
public StreamedContent getImageF() {
if (student.getImage() != null) {
InputStream is = new ByteArrayInputStream(student.getImage());
System.out.println("Byte :"+student.getImage());
content = new DefaultStreamedContent(is, "", student.getStuID());
System.out.println("ddd ------------------------------- " + content);
return content;
}
return content;
}
Run Code Online (Sandbox Code Playgroud)
这将返回一个空白图像.这是怎么造成的,我该如何解决?
标准输出打印以下内容:
INFO: Byte :[B@a2fb48
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@b0887b
INFO: Byte :[B@a2fb48
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@1d06a92
INFO: Byte :[B@d52f0b
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@39a60
INFO: Byte :[B@d52f0b
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@8c3daa …Run Code Online (Sandbox Code Playgroud)