【发布时间】:2015-05-03 19:14:32
【问题描述】:
我正在使用 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 这是显示摆动图像的快速测试代码。
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 的应用程序的更新。
提前感谢您的建议。
【问题讨论】:
标签: java jsf primefaces