3 페이지 뷰가있는 웹 앱이 있습니다.playframework에 검색 기능을 구현하는 것에 대해 의문이있다.
1.an index
dB의 모든 Item
의이 나열되는 페이지 만 Item
최신와 creationDate
의 세부 사항이 표시됩니다.
2.An itemDetails
페이지 선택한 항목의 세부 정보가 표시됩니다.이 페이지에는 또한 db의 모든 항목이 나열됩니다.
나열된 항목을 클릭하면 세부 정보 페이지가 나타납니다.
는 (이 두 페이지는 사용자가 항목 이름을 일치하는 검색 할 단어를 입력 할 수있는 텍스트 입력 필드가 포함되어 있습니다.) 검색과 일치하는 항목의 목록을 보여줍니다
3.A search
결과 페이지를, 질문.
첫 번째 두 페이지를 구현하고 정적 공용 함수를 만들었습니다. 이제 검색을 구현하고 싶습니다. 검색 결과를 나열하는 함수와 결과 페이지를 만들었습니다.
내 문제는 검색 결과에서 항목을 클릭하면 해당 항목 and a listing of all items in db
의 세부 정보를 표시하는 itemDetails 페이지가 표시됩니다. 그 이유는 itemDetails 기능이 구현 된 방식이기 때문입니다. 항목 and items which were results of the search query
의 세부 사항을 보여주는 페이지로 이동하십시오. 상태가 두 요청 사이에 유지되지 않으므로 위의 구현에서 가능하지 않다는 것을 알고 있습니다.
내가 어떻게해야합니까? 나는 이것에 대해 명확하게 생각할 수 없습니다. 약간의 빛을 줄 수 있습니까?
내가 가진 당분간 ..for 인덱스 페이지와 유사하다 : index.html 페이지가
#{extends 'main.html' /}
#{set title:'Home' /}
#{if item}
//show the details of item
#{/if}
#{if items.size()>0}
#{list items:items, as:'item'}
<a href="@{Application.itemDetails(item.id)}">${item.name}</a>
#{/list}
#{/if}
#{else}
There are currently no items
#{/else}
#{form @Application.search(keyword)}
<input type="text" name="keyword" id="keyword" size="18" value=""/>
<input type="submit" value="search"/>
#{/form}
itemDetails.html 페이지입니다
package controllers;
...
public class Application extends Controller {
...
public static void index() {
//all items
List<Item> items = Item.find("order by creationDate desc").fetch();
//the latest created item
Item item = items.get(0);
render(items,item);
}
public static void itemDetails(Long id) {
//selected item
Item item = Item.findById(id);
//all items
List<item> items = Item.find("order by creationDate desc").fetch();
render(items,item);
}
public static void search(String keyword) {
String kw = keyword.trim();
String pattern = "%"+kw+"%";
String query="select distinct item from Item item where item.name like :pattern";
List<Item> items = Item.find(query).bind("pattern", pattern).fetch();
render(items);
}
...
}
처럼
코드는 색인 페이지의 모든 내용을 복사했습니다.
검색 페이지 : 나는 몇 가지 가능성을 참조
#{extends 'main.html' /}
#{set title:'search results' /}
#{if items.size()>0}
#{list items:items, as:'item'}
<a href="@{Application.itemDetails(item.id)}">${item.name}</a>
#{/list}
#{/if}
#{else}
<div class="empty">
could not find items with matching name here.
</div>
#{/else}
'키워드'는 검색 결과 페이지로 전송되어야합니다. – Ryan