我想做一些简单的事情:在单列的表中显示Java列表的内容。问题是:表格应该出现的地方,什么都没有显示。
查看代码:
佩斯奎萨豆.java
private String title;
List<String> uriByTitle = new ArrayList<String>();
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getUriByTitle() {
for( String s : this.uriByTitle ) { //test
System.out.println(s);
}
return uriByTitle;
}
public void search() {
this.searchUriByTitle();
System.out.println("1: " + this.uriByTitle); //test
}
public void searchUriByTitle() {
RDFNode uri;
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?document WHERE { " +
"?document dc:title ?title." +
"FILTER (?title = "" + this.getTitle() + "" ). }";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, databaseModel);
ResultSet results = qe.execSelect();
while( results.hasNext() ) {
QuerySolution querySolution = results.next();
uri = querySolution.get("document");
ResourceImpl resourceImpl = (ResourceImpl) uri;
this.uriByTitle.add(uri.toString()); //adding elements
}
qe.close();
}
在上面的代码中,我进行了 2 次测试:1-尝试在search()
方法内部打印变量uriByTitle
的值,2-尝试在getUriByTitle()
方法中打印它。在 search()
内部的测试中,我在 Eclipse 控制台上打印了正确的内容,但在getUriByTitle()
内部的测试中,我什么也没打印出来。
查看代码的另一部分:
佩斯奎萨文档.xhtml
<h:body>
<h:form enctype="multipart/form-data">
<h:panelGrid columns="2">
Titulo: <h:inputText value="#{pesquisaBean.title}" />
<h:commandButton value="Procurar" action="#{pesquisaBean.search()}" />
</h:panelGrid>
<rich:dataTable>
<a4j:repeat value="#{pesquisaBean.uriByTitle}" var="uri" >
<rich:column>
<f:facet name="header">URI</f:facet>
#{uri}
</rich:column>
</a4j:repeat>
</rich:dataTable> <br />
</h:form>
</h:body>
这里有什么问题?谢谢!
您正在为"getUriByTitle"返回的列表中的每个元素创建一个列。这不是你使用rich:dataTable
的方式.试试这个:
<rich:dataTable value="#{pesquisaBean.uriByTitle}" var="uri">
<rich:column>
<f:facet name="header">URI</f:facet>
#{uri}
</rich:column>
</rich:dataTable>