3 Replies Latest reply on Dec 2, 2009 6:08 PM by thelonius

    Navigation problems

    thelonius

      Hello everybody!
      I recently started working with JBoss Seam and am amazed by the potential of this framework. However there is one issue I could not tackle so far. It is page navigation. I already read through quite some tutorials and examples and am convinced that my settings are correct, however when I run my website i do not get redirected.


      (Code follows)
      If I enter a search term on my home.xhtml and click the search button Seam does call the search function, however after it successfully finished (and found the correct amount of list items) I end up on the home.xhtml again, as if nothing happened, instead of being redirected to search_result.xhtml. This is only one example, redirects on other pages, like registration, do not work either.


      Can anyone see what I am doing wrong?
      Any help is greatly appreciated.
      Cheers,
      Ole



      home.page.xml


      <?xml version="1.0" encoding="UTF-8"?>  
       <page xmlns="http://jboss.com/products/seam/pages"  
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
             xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">  
         
          <navigation from-action="#{itemFinder.search}">  
             <rule>  
                <redirect view-id="/search_result.xhtml"/>  
             </rule>  
          </navigation>  
         
       </page>
      




      ItemFinderBean.java


       @Stateful  
       @Name("itemFinder")  
       public class ItemFinderBean implements ItemFinder {  
         
           static final String EJBQL = "select item from Item item ";  
         
           @PersistenceContext  
           EntityManager em;  
         
           @In  
           @Out(required = false)  
           String criteria;  
         
           @DataModelSelection  
           @Out(required=false)  
           Item item;  
         
           @DataModel  
           private List<Item> results;                   
         
           public void search() {                
               StringBuilder searchPattern = new StringBuilder();  
               searchPattern.append("%");  
               if (criteria != null && criteria.trim().length() != 0) {  
                   searchPattern.append(criteria.toLowerCase().replace('*', '%')).append('%');  
               }  
               results = em.createQuery(EJBQL +  
                                                    "WHERE lower(item.title) LIKE :search " +  
                                                      "OR lower(item.description) LIKE :search")  
                       .setParameter("search", searchPattern.toString()).getResultList();  
           }  
         
           public void showItem() {  
               if (item == null) throw new ItemNotFoundException();  
           }  
         
           @Remove @Destroy  
           public void destroy(){}  
       }
      
      



      Snippet from home.xhtml



       
      <h:form>  
           <table>  
                 <tr>  
                          <td><h1>Suche</h1></td><td><h:inputText value="#{criteria}" /></td>  
                          <td><h:commandButton type="submit" value="Finden!"  
                          action="#{itemFinder.search}" /></td>  
                    </tr>  
               <tr><td></td><td><a >Erweiterte Suche</a></td></tr>                       
           </table>  
       </h:form>
      



        • 1. Re: Navigation problems
          clerum

          Try


          <page xmlns="http://jboss.com/products/seam/pages"  
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
                 xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">  
              
              <navigation from-action="#{itemFinder.search}">  
                 <redirect view-id="/search_result.xhtml"/>  
              </navigation>
             
           </page>
          



          I beleive if you are using <rule> you need to be either checking if-outcome or if


          <xs:attributeGroup name="attlist.rule">
          <xs:attribute name="if-outcome" type="pages:outcome-expression"/>
          <xs:attribute name="if" type="pages:boolean-value-expression"/>
          </xs:attributeGroup>
          



          Since your method is void and you want to always redirect to /search_results.xhtml you don't need a rule. Your just triggering based on the action method which was called #{itemFinder.search}

          • 2. Re: Navigation problems
            thelonius

            Hi Cody!
            Thanks for your fast reply. Unfortunately the solution suggested does not work either. There is simply nothing happening (except the function being called).
            However if I return a String in the function (return "/search_result.xhtml";) I get the intended result. But I would rather have the navigation rules detached from my functions, because I believe functions should only return values that are actually logically returned by the function, not those that just define the pageflow.


            I read somewhere that an empty <rule> tag catches all non-null returns including voids, but a null return causes an error, if no <rule> tag is defined every return is being caught. So in my case the empty <rule> tag should have been identical to no <rule> tag, no?


            --Ole

            • 3. Re: Navigation problems
              thelonius

              Does anyone else maybe have an idea, why the xml-based navgiation does not work for me?