在JSF中有很多材料区分value属性和binding属性.
我对这两种方法如何彼此不同感兴趣.鉴于:
public class User {
private String name;
private UICommand link;
// Getters and setters omitted.
}
Run Code Online (Sandbox Code Playgroud)
<h:form>
<h:commandLink binding="#{user.link}" value="#{user.name}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
value指定属性时会发生什么变化.getter运行以返回bean 的name属性值User.该值将打印到HTML输出.
但我无法理解它是如何binding运作的.生成的HTML如何维护与bean link属性的绑定User?
下面是手动美化和注释后生成的输出的相关部分(注意id j_id_jsp_1847466274_1是自动生成的,并且有两个隐藏的输入小部件).我正在使用Sun的JSF RI 1.2版.
<form action="/TestJSF/main.jsf" enctype="application/x-www-form-urlencoded"
id="j_id_jsp_1847466274_1" method="post" name="j_id_jsp_1847466274_1">
<input name="j_id_jsp_1847466274_1" type="hidden" value="j_id_jsp_1847466274_1">
<a href="#" onclick="...">Name</a>
<input autocomplete="off" id="javax.faces.ViewState" name="javax.faces.ViewState"
type="hidden" value="-908991273579182886:-7278326187282654551">
</form>
Run Code Online (Sandbox Code Playgroud)
在哪里binding存放在这里?
我想显示的保存在数据库中的图像字节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) jsf ×2
jsf-2 ×2
binding ×1
components ×1
database ×1
field ×1
image ×1
java ×1
primefaces ×1
transient ×1