2 Replies Latest reply on Jan 19, 2010 12:05 PM by vdeminico

    restful search using param

    vdeminico

      Hi,
      I have a question about the use of f:param attribute to build a restful url. The scenario is simple. I have a suggestionbox seam component for autocompletion. It's a search textfield. When I submit a request, I'd want to build a restful request based on the data selected on the suggestionbox component.


      The home.xhtml fragment is:



      <h:form>
                    <h:outputLabel value="#{messages['home.label.searchText']}" for="searchText" />
                    <h:inputText id="searchText" 
                              value="#{searchTextAction.selectedSearchItem}"
                               converter="#{searchItemConverter}"/>
                    <rich:suggestionbox id="searchSuggestionbox"
                          for="searchText" var="item" fetchValue="#{item.nome}"
                          suggestionAction="#{searchTextAction.suggestSearchItems}"
                          minChars="2" value="#{searchTextAction.selectedSearchItem}" height="300" width="200">
                          <h:column>
                               <h:outputText value="#{item.searchItemText}" />
                          </h:column>
                     </rich:suggestionbox>
                     
                     <s:link value="Cerca" view="/search.xhtml">
                          <f:param name="prefix" value="bedandbreakfast"/>
                          <f:param name="sid" value="#{searchTextAction.selectedSearchItem.sid}"/>
                          <f:param name="suffix" value="#{searchTextAction.selectedSearchItem.url}"/>
                     </s:link>
                </h:form>
      



      when the user submit the form through s:link, it creates a GET request and, as expected, it appends the three params to the URL. Obviously it can't retrieve values for param sid and suffix because they are calculated on the server. There is a solution to this problem????


      Thanks,
      Valerio.

        • 1. Re: restful search using param
          daxxy

          Valerio, you cannot submit form data using s:link.


          I have only recently started understanding this myself.  Here you might find a good explanation.


          http://seamframework.org/Community/UnderstandingSbuttonHcommandButtonAndRequestParameter


          I think you want to use h:commandLink to submit the input.  Then in search.page.xml you want to wire your parameters to the searchTextAction bean like this



          
          <param name="prefix" value="bedandbreakfast"/>
          <param name="sid" value="#{searchTextAction.selectedSearchItem.sid}"/>
          <param name="suffix" value="#{searchTextAction.selectedSearchItem.url}"/>





          These parameters will get set before search.xhtml is rendered and will result in a URL somewhat like this




          search.seam?prefix=bedandbreakfast&sid=<searchTextAction.selectedSearchItem.sid here>&suffix=<searchTextAction.selectedSearchItem.url here>





          • 2. Re: restful search using param
            vdeminico

            Ok, thanks for your reply Tanya.
            Now I have an url like this:




            search.seam?regione=CAMPANIA&provincia=BENEVENTO&comune=APOLLOSA&cid=9
            




            I'd want a restful url, like



            /prefix/CAMPANIA/BENEVENTO/APOLLOSA
            



            Normally I do it using the seam (third part) url rewrite filter, but now it doesn't work. This behaviour is correct, because the filter acts before the jsf one. For me it's impossible to solve the problem without using an explicit re-rendering.


            Any ideas?


            Valerio.