我知道这个问题被多次询问过,我读了很多这些问题,但我觉得我缺少基本的,所以它对我不起作用..
(项目在JSF2,Netbeans 7.3beta,Glassfish3 ..和用WCF编写的Web服务) 我已经做了什么:
看看我的简单代码(我有index.html,在那里我显示DataTable,在我的managedbean中创建) 的index.html
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head><title>IGNORED</title></h:head>
<h:body>
<ui:composition template="/templates/masterPage.xhtml">
<ui:define name="content">
<h:form>
<h3>and #{bean.tst}!</h3>
<p:dataTable value="#{bean.rows}" var="row">
<p:columns value="#{bean.columns}" var="column" headerText="#{bean.headers[column]}">
#{row[column]}
</p:columns>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
和.. bean.java
@Named(value = "bean")
@SessionScoped
public class Bean implements Serializable {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_62599/TestService.svc.wsdl")
private TestService service;
... // list, maps.. not important for this example
public Bean() {
columns = new ArrayList<String>();
rows = new ArrayList<Map<String, Object>>();
headers = new HashMap<String,String>();
// Columns:
for(int i = 0 ; i < 4 ; i++)
{
String column_id = "c" + i;
String column_name = "Column name " + i;
columns.add(column_id);
headers.put(column_id, column_name);
}
// Rows:
for(int i = 0 ; i < 100 ; i++)
{
Map<String,Object> m = new HashMap<String,Object>();
m.clear();
for(int j = 0 ; j < 4 ; j++)
{
**// HERE IT DOESNT WORK in table i've got Content:Null**
m.put("c" + j, "Content:" + Tst);
}
rows.add(m);
}
}
private String Tst;
public String getTst() {
return doWork("Test");
}
private String doWork(java.lang.String str) {
DataTable.ITestService port = service.getBasicHttpBindingITestService();
return port.doWork(str);
}
}
为什么我不能在托管bean中使用它?我做错了什么?我想在bean中使用它,所以我可以填充我的DataTable ......