0
votes

I'd like to do something simple: show the content of a Java list in a table of a single column. The problem is: where the table was supposed to appear, nothing is shown.

Look at the code:

PesquisaBean.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(); 
        }

On the code above I made 2 tests: 1-tried to print the value of the variable uriByTitle inside of the search() method and 2-tried to print it inside of the getUriByTitle() method. On the test inside of search() I get the correct content printed at my Eclipse console, but on the test inside of the getUriByTitle() I get nothing printed.

Look at the other part of the code:

pesquisaDocumento.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> 

Whats the problem here? Thank you!

1

1 Answers

0
votes

You are creating one column for each element in the list returned by "getUriByTitle". That's not how you use rich:dataTable. Try this:

<rich:dataTable value="#{pesquisaBean.uriByTitle}" var="uri">
    <rich:column>
        <f:facet name="header">URI</f:facet>
        #{uri}
    </rich:column>
 </rich:dataTable>