Pergunta

I have a page to search for authors. It should show the information about the found author or show a message when the author is not found.

I'm trying to use <rich:notifyMessage>, but the problem is that when I use it, the results from the found authors don't appear and, also, the message appear on the right up corner of the page and I'd like it to appear bellow the panel, where the search results would appear.

Look at how I'm doing that, is there a better way to do it?

xhtml

    <h:form>
  <br />
    <br />
     Insert Author
     <br />
     <br />
     <br />
     <rich:panel id="panel" style="width:310px">
      <f:facet name="header">Search for the author you want to insert</f:facet>
       <h:panelGrid columns="3">
          Name: <h:inputText value="#{insertAuthorController.nameToSearch}" />  

           <a4j:commandButton value="Search" action="#{insertAuthorController.searchAuthor()}">
           </a4j:commandButton>
       </h:panelGrid>  
   </rich:panel> 
       <br />     
        <rich:notifyMessage/>

       <rich:dataTable value="#{insertAuthorController.authorListOfMap}" var="result">
            <c:forEach items="#{insertAuthorController.variableNames}" var="vname">
                 <rich:column>
                     <f:facet name="header">#{vname}</f:facet>
                      #{result[vname]}
                 </rich:column> 
            </c:forEach>    
       </rich:dataTable>
       <br />
       <h:commandButton value="Go to insert page" action="#{insertAuthorController.searchAuthor()}" />
    </h:form>

Bean

public void searchAuthor() {
        this.variableNames.clear();
        List<String> uris = new ArrayList<String>();

        uris = this.authMapper.searchAuthorUriByName(this.nameToSearch);

        if( (uris != null) && (!uris.isEmpty()) ) {

         for( String uri : uris ) {
            Map<String, String> map = new HashMap<String, String>();
            String name = this.authMapper.searchNameByAuthorUri(uri);
            String email = this.authMapper.searchEmailByAuthorUri(uri);

            map.put("URI", uri);
            map.put("Nome", name);
            map.put("Email", email);
            authorListOfMap.add(map);   
        }
          this.addVariableNames();
        } else {
            FacesContext ctx = FacesContext.getCurrentInstance();
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Detail","Author not found!"); //FacesMessage has other info levels
            ctx.addMessage(null,msg);
        }
    }

Thank you!

Foi útil?

Solução

The notifyMessage is supposed to behave like that (i.e. pop up in the corner of the screen), if you want just a simple text message use <rich:message>.

Or in this simple case you can check if the result returned something:

<h:outputText value="No results" 
    rendered="#{fn:length(insertAuthorController.authorListOfMap) == 0}">

Your table doesn't show up because you need to rerender it if you want to see the changes:

<rich:dataTable id="authorsTable" …>

<a4j:commandButton … render="authorsTable" />
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top