- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Primefaces p:graphicImage 来显示每个登录用户的图像。除了我的照片看起来像底片外,一切都很好。我做错了什么。这是我的代码:
<sec:authorize access="isAuthenticated()">
<span>
<p:graphicImage value="#{currentUser.image}" class="img-thumbnail pull-right"
height="80px;" width="80px;" >
<f:param name="id" value="#{request.remoteUser}" />
</p:graphicImage>
</span>
.....
And here is the JSF Managed Bean
@Named(value = "currentUser")
@ApplicationScoped
public class CurrentUser implements Serializable {
@EJB
private VempDetailsFacade vempDetailsFacade;
private VempDetails details;
public StreamedContent getImage() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the HTML. 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 imageId = context.getExternalContext().getRequestParameterMap().get("id");
details = vempDetailsFacade.find(imageId);
if (details != null) {
try {
return new DefaultStreamedContent(new ByteArrayInputStream(details.getEmpImage()));
} catch (Exception e) {
System.err.println("No Image Retrieved : "+e.getMessage());
}
}
return null;
}
}
public VempDetails getDetails() {
return details;
}
public void setDetails(VempDetails details) {
this.details = details;
}
@PostConstruct
public void init() {
details = vempDetailsFacade.
find(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
}
}
我可能做错了什么。同样的图片在一个普通的swing应用程序中显示没有任何问题
代码更新
@BalusC下面是在 swing 上显示图像的快速测试代码。
public DisplayImage() {
super("Image Display");
setSize(600, 600);
connection = getConnection();
try {
statement = connection
.prepareStatement("SELECT empImage FROM v_empDetails WHERE empCode=?");
statement.setString(1, "009");
result = statement.executeQuery();
byte[] image = null;
//just a result anyway
while (result.next()) {
image = result.getBytes(1);
}
Image img = Toolkit.getDefaultToolkit().createImage(image);
ImageIcon icon = new ImageIcon(img);
JLabel lPhoto = new JLabel();
lPhoto.setIcon(icon);
add(lPhoto);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setVisible(true);
}
public Connection getConnection() {
Connection connection = null;
........
难道是Toolkit.getDefaultToolkit().createImage(image);行正在重新反转。这些图像是使用不同的应用程序填充的,这更像是一种更新,将其作为基于 Web 的应用程序。
提前感谢您的建议。
最佳答案
JSF/PrimeFaces 只是呈现器,根本不会反转图像。否则世界上任何其他使用 JSF/PrimeFaces 的人都会面临同样的问题。你的问题更深层次。更有可能的是,图像已经作为底片存储在数据库中,并且您现有的 Swing/Java2D 代码的编写方式使其在显示之前重新反转图像,可能是在编写错误的调整大小/裁剪过程中。
因此,要解决此问题,请重新关注负责将这些图像存储在数据库中的代码(并且不要忘记修复 Swing/Java2D 代码以不再重新反转这些代码)。
关于java - 图像显示使用 p :graphicImage. 图片看起来像负片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018237/
我在使用 Omnifaces 2.1 时遇到了问题。 我有一个图像类型byte[]存储在我的数据库中,其声明java类如下: @Lob private byte[] image; 在我的 x
我正在使用 primeFaces 在它的 detailView 中显示系列的封面图像。我的问题是,它总是显示相同的图片,除非我刷新缓存(Chrome 中的 Strg+F5)。 我的显示图片的代码如下
我在使用 Omnifaces 2.1 时遇到了问题。 我有一个图像类型byte[]存储在我的数据库中,其声明java类如下: @Lob private byte[] image; 在我的 x
我正在使用 primeFaces 在它的 detailView 中显示系列的封面图像。我的问题是,它总是显示相同的图片,除非我刷新缓存(Chrome 中的 Strg+F5)。 我的显示图片的代码如下
我想要一个按钮和一个图形图像。默认情况下,不显示图形图像。如果用户单击该按钮,则会显示图形图像(呈现 = 真)。 我可以做到,但我必须刷新页面才能看到显示的图形图像。 我想我必须使用 ajax 组件来
我从数据库加载了一个图像 byte[] 。有谁有一个关于如何将其变成 StreamedContent 的 Bean 示例吗?对象并在 中使用它? 谢谢。 最佳答案 @Named public cla
我有以下标签: 在我的文件夹中,我有以下结构: /resources/images/..... /WEB-INF/.... /*.xhtml 渲染时,该图像显示为: 但是我确实看到其他使用资源的东
当我检索服务器路径并显示到 p:graphicImage 中时标签,则不显示图像。图像加载到 webbapp 文件夹之外。图片的服务器路径是这样的\\qbsserver\Test Folder\tes
not working in jsf
我最近加入了一个 在我的 JSF 页面中,如 PrimeFaces 展示中所示。代码执行时没有任何错误,但不显示任何图像。我认为这是由于图像的路径格式不正确造成的。这是怎么引起的,我该如何解决? in
您知道带有国际化标志的网站,单击这些网站即可获得所需的语言。这就是我想用 JSF 标签实现的任务。 编辑:当我按语言图标时没有任何反应。 这是我的 xhtml。
我正在使用 h:graphicImage 使用 name 显示图像属性。现在,为了成功实现PrettyPhoto (JQuery implementation) ,我需要图像的结果路径( /javax
我正在使用 Primefaces p:graphicImage 来显示每个登录用户的图像。除了我的照片看起来像底片外,一切都很好。我做错了什么。这是我的代码:
尝试获取一个 blob 并将其变成流媒体内容。我得到了字节,它们确实被转换成 ByteArrayInputStream 并且我正在返回 StremedContent 图像,但我一直得到这个:
我使用 c:forEach 循环使用 h:graphicImage 显示图像列表。但我无法显示图像。我的页面中也有 h:commandLink 。图像必须在表单初始化时显示。但它不起作用。但点击h:c
您好,我有一个 graphicalImage,我希望在单击图像时启动 backingBean 中的一个方法。下面是我正在使用的代码片段,但它不起作用。请帮忙。 最佳答案 您需要将其包装在 中或 并
我在 index.xhtml 文件中显示图像时遇到问题。 我希望我的数据库中的链接指向图像文件,以便 或 标签可以显示它。目前仅使用本地主机。 我设法将图像保存到 c:\var\webapp\imag
我想从每次运行都会更改的 xhtml 文件在 jsf Web 应用程序中显示图形图像。上传完成后,我正在显示图像。但是发生的事情是在上传任何图像后,它总是显示我第一次上传的那个。在刷新时显示最近上传的
我正在尝试使用 p:graphicImage 标记动态显示素面中的图像,如下所示: ` 托管bean如下: @ManagedProperty("#{param.imageName}") p
not rendering image
我有一个 JSF 页面,我想在其中显示图像。图像作为 blob 存储在数据库中。实体看起来像这样: @Entity public class Player { @Id @Generat
这个问题在这里已经有了答案: Load images from outside of webapps / webcontext / deploy folder using or tag (4 个
我是一名优秀的程序员,十分优秀!