4 Replies Latest reply on Oct 31, 2007 10:51 AM by Sebastian Stenerdal

    Problems when paginating with search criterias

    Sebastian Stenerdal Newbie

      Hi!

      I've combined the seam reference's pagination and search criteria-examples in the entity-query section, and it's working great. Two problems though:

      1. When moving between search pages, letters like åäö in the search field become corrupted. Perhaps this has to do with how they are read from the url-string?

      2. If I'm at page 3, change the criteria and click 'search', I'm still at page 3, even if the new search only has a single page of results.

      I'm using seam 1.2.1GA. If any code examples are important here, just let me know. Although I've basically just copied the examples and combined them.

      Regards,
      Sebastian

        • 1. Re: Problems when paginating with search criterias
          Sebastian Stenerdal Newbie

          This is the code as it looks now. One problem is that the s:links put the searchCriteria as a get-parameter, which messes up some characters. Is it possible to html-encode it in some way?

          I tried to solve problem no2 by adding a hidden field in the search-form, which sets firstResult to 0, but that didn't do anything, perhaps because get-parameters are prioritized over post-parameters?

          components.xml:

          <fwk:entity-query name="users"
           entity-manager="#{entityManager}"
           ejbql="from User"
           order="name"
           max-results="10">
           <fwk:restrictions>
           <value>lower(name) like lower(concat(#{searchCriteria},'%'))</value>
           </fwk:restrictions>
          </fwk:entity-query>
          


          pages.xml:
          <page view-id="/listUsers.xhtml">
           <param name="firstResult" value="#{users.firstResult}"/>
           <param name="searchCriteria" value="#{searchCriteria}"/>
          </page>
          


          listUsers.xhtml:
          <h:form>
           <h:inputText name="searchCriteria" value="#{searchCriteria}"/>
           <h:commandButton value="Search"/>
          </h:form>
          <h:dataTable value="#{users.resultList}"var="user">
           <h:column>
           <s:link view="/viewUser.xhtml" value="#{user.name}">
           <f:param name="userId" value="#{user.id}"/>
           </s:link>
           </h:column>
          </h:dataTable>
          <s:link rendered="#{users.previousExists}" value="First">
           <f:param name="firstResult" value="0"/>
          </s:link>
          <s:link rendered="#{users.previousExists}" value="Previous">
           <f:param name="firstResult" value="#{users.previousFirstResult}"/>
          </s:link>
          <s:link rendered="#{users.nextExists}" value="Next">
           <f:param name="firstResult" value="#{users.nextFirstResult}"/>
          </s:link>
          <s:link rendered="#{users.nextExists}" value="Last">
           <f:param name="firstResult" value="#{users.lastFirstResult}"/>
          </s:link>
          


          Thanks in advance
          Sebastian

          • 2. Re: Problems when paginating with search criterias
            Pete Muir Master

            What is character encoding set to?

            • 3. Re: Problems when paginating with search criterias
              Sebastian Stenerdal Newbie

              Hi!
              Thanks for your response.

              All I've specified is the content-type (as an html meta-tag) in my template, which is set to utf-8.

              Though now when you mentioned it, I looked through the seam reference again and added this to my components.xml.

              <web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.seam"/>

              Although, that didn't make any difference either. Should I add the encoding to some other place as well?

              The URL is formed correctly, but in the input-field, "åaa" has become "Ã¥aa".
              Note that this only occurs after going between result-pages (with the s:links). The initial search (with the h:commandButton) works fine.

              • 4. Re: Problems when paginating with search criterias
                Sebastian Stenerdal Newbie

                After a lot of trying around, I've put the search criteria-string into an object, so that I can control the getter and setter for it.

                With the setter looking like this

                this.criteria = new String(criteria.getBytes("ISO-8859-1"), "UTF-8");
                


                The search works when the criteria is sent as a page parameter, though it breaks the original form-request.

                My conclusion based on this is that the form sends a utf-8-encoded string, but the get-request parameter is ISO-8859-1-encoded.

                If this seems like a reasonable explanation, is there a way around this? Where can I set the encoding for the page parameters?