2012-03-12 4 views
1

いくつかのajaxコンポーネントとコントローラメソッドの呼び出しに基づいて検索結果を生成するページがある場合、そのページの状態を保存する最良の方法は検索結果)を表示して、セッションのどの時点でもそのページを再度表示することができますか?Grails - ajaxコンポーネントを使用した状態/ Webフローの保存

1)検索結果を得る 2)別のページに変更を加える 3)検索結果に戻る1と同じページが表示されます。

私はWebフロー(必要以上に不必要であり、正式なものだと感じています)とAJAXセーブステートについて読んだことがありますが、間違っているようです。またGrailsがこの機能(ウェブフレームワークでは不思議そうな機能)を持って箱から出てこないのも見ました。

編集:私はそのセッションのために、コールによって移入さにsearchResultsリストは、私のコントローラを形成することを保つにはどうすればよい

?私は自分のロジックとセッションの保存の間にその橋が見当たりません。

class SearchService { 

boolean transaction = false 
static scope = 'session' 
def searchResults 

private Contact[] updateContactSearchList(String ns, Company c, String si, String res) { 

    def nameSearch = ns 
    def company = Company.get(c?.id) 
    def showInactives = si 
    def reset = res 

    if(res == "true") { 
     render(template:'searchResults', model: [searchResults:"", total: 0]) 
     return 
    } 

    if(showInactives == "on" && nameSearch == "" && company != null) { 

     searchResults = Contact.withCriteria { 
      eq('company', company) 
      and { 
       eq('isActive', false) 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 
    } 
    else if(showInactives == "on" && nameSearch == "" && company == null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', false) 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 
    } 
    else if(showInactives == "on" && nameSearch != "" && company != null) { 

     searchResults = Contact.withCriteria { 
      eq('company', company) 
      and { 
       eq('isActive', false) 
      } 
      or { 
       ilike('firstName', '%' + nameSearch + '%') 
       ilike('lastName', '%' + nameSearch + '%') 
       ilike('fullName', '%' + nameSearch + '%') 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 
    } 
    else if(showInactives == "on" && nameSearch != "" && company == null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', false) 
      or { 
       ilike('firstName', '%' + nameSearch + '%') 
       ilike('lastName', '%' + nameSearch + '%') 
       ilike('fullName', '%' + nameSearch + '%') 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 

    } 

    else if(showInactives == null && nameSearch == "" && company != null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', true) 
      and { 
       eq('company', company) 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 

    } 
    else if(showInactives == null && nameSearch == "" && company == null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', true) 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 

    } 
    else if(showInactives == null && nameSearch != "" && company != null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', true) 
      and { 
       eq('company', company) 
      } 
      or { 
       ilike('firstName', '%' + nameSearch + '%') 
       ilike('lastName', '%' + nameSearch + '%') 
       ilike('fullName', '%' + nameSearch + '%') 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 

    } 
    else if(showInactives == null && nameSearch != "" && company == null) { 

     searchResults = Contact.withCriteria { 
      eq('isActive', true) 
      or { 
       ilike('firstName', '%' + nameSearch + '%') 
       ilike('lastName', '%' + nameSearch + '%') 
       ilike('fullName', '%' + nameSearch + '%') 
      } 
     } 
     searchResults.sort{it.lastName} 
     return searchResults 

    } 
    else { 
     //log error 
    } 
} 

}

+0

Redisプラグインは、このようなものをキャッシュする(パフォーマンス目的のために、またはあなたの場合は、歴史的な目的のためには何かのように思われる)ために、このようなものの良い動きかもしれません。それをチェックしてください:http://grails.org/plugin/redis –

答えて

0

私はセッションを作成する推薦するサービスをスコープ、例えば:

class SearchService { 
    static scope = "session" 
    def results 

} 

これは、検索エンジンへの要求を処理し、「結果」のオブジェクトに格納します。次に、Webコンポーネントのjavascriptは、同じ結果が必要な場合は、クエリーを再サブミットする必要なく、このオブジェクトに直接アクセスしてレンダリングする必要があります。

+0

これは私には若干です - 私のコントローラはセッションを保存するサービスをどのように呼び出しますか?検索ロジックをサービスに移さなければならないのですか? – user82302124

+0

サービスにロジックを追加しました。結果オブジェクトがアプリケーションのセッション中どのように永続化されるかを理解するだけでいいですか?今は検索ページを離れて帰ってきて、何も保存しません。再度、感謝します! – user82302124

+0

NM - それを得ました。私を良い場所に連れてくれてありがとう! – user82302124

関連する問題