0
我不能例如在我的自定義控制使用任何bean值: 使用來自豆類值:不能Facelets中的自定義組件
這是我的foo.taglib.xml文件。
<facelet-taglib>
<namespace>http://www.penguenyuvasi.org/tags</namespace>
<tag>
<tag-name>test</tag-name>
<component>
<component-type>test.Data</component-type>
</component>
</tag>
</facelet-taglib>
faces-config.xml中
<component>
<component-type>test.Data</component-type>
<component-class>test.Data</component-class>
</component>
test.Data類
package test;
import java.io.IOException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
public class Data extends UIComponentBase {
private Object msg;
@Override
public String getFamily() {
return "test.Data";
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
super.encodeBegin(context);
context.getResponseWriter().write(msg.toString());
}
public void setMsg(Object msg) {
this.msg = msg;
}
}
Bean.java:
package test;
public class Bean {
private String temp = "vada";
public String getTemp() {
return temp;
}
}
test.xhtml(不工作)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://www.penguenyuvasi.org/tags">
<py:test msg="#{bean.temp}" />
</html>
test.xhtml(作品)
<py:test msg="#{bean.temp}" />
非常感謝。優秀的解決方 附加信息:不建議使用ValueBinding。應該使用ValueExpression。 – 2009-09-15 16:05:35
是的,的確,必須使用ValueExpression。 – romaintaz 2009-09-15 16:18:03
ValueExpression ve = getValueExpression(「msg」);如果(ve!= null){ } return(String)ve.getValue(getFacesContext()。getELContext()); } – 2009-09-16 05:25:57