Adding a Portlet to the CONTROL PANEL

목표 : 관리자 측면에서 새로운 Guestbook entity를 추가할 수는 있었지만 지우는 기능은 없었다. 그리고 guestbook entity의 이름을 변경하거나 Permission 설정을 할 수가 없었다. 그래서 이번 페이지에서는 Guestbook Admin이라는 portlet을 만들어서 이런 기능들을 추가하고, Control panel에 추가해볼 것이다.

기존의 Guestbook portlet에 새로운 lIferay portlet 생성 (New -> Liferay Portlet)

변화된 점

  • portlet.xml : <portlet> element가 추가됨 ※ portlet.xml의 역할 ; defines portlet attributes specified by the JSR-286 portlet specification
  • liferay-portlet.xml : <portlet> element가 추가됨 ※ liferay-portlet.xml의 역할 : defines Liferay-specific portlet attributes
  • liferay-display.xml : <category> 가 하나 추가됨 (category.hidden -> Dock bar에선 보이지 않음, Control panel로만 접근가능)

구현 순서

  1. GuestbookLocalServiceImpl에 service 추가

  2. GuestbookAdminPortlet에 action method 추가

  3. Guestbook Admin portlet을 위한 user interface 추가

1.GuestbookLocalServiceImpl 구현

  • updateGuestbook method 추가

  • deleteGuestbook method 추가

  • getGuestbooksCount method 추가

※ 중요한 점은 resource도 같이 update, delete 해줘야 된다는 것!

2.GuestbookAdminPortlet 구현

-LocalServiceImpl에서 구현한 add, update, delete method를 이용해서 action method를 구현한다.

Separation of Concerns : Portlet clasess (call ->) Services (call ->) Persistence layer

  • addGuestbook method 추가 (GuestbookLocalServiceUtil.addGuestbook method 이용)

  • updateGuestbook method 추가 (GuestbookLocalServiceUtil.updateGuestbook method 이용)

  • deleteGuestbook method 추가 (GuestbookLocalServiceUtil.deleteGuestbook method 이용)

3.Guestbook Admin portlet을 위한 user interface 구현 <liferay-ui:search-container> tag에 대한 설명

  • <liferay-ui:search-container-results>, <liferay-ui:search-container-row>, <liferay-ui:search-iterator> 를 내부에 가져야 함.

  • <liferay-ui:search-container-results> : results attribute uses a service call(GuestbookLocalServiceUtil) to retrieve a list of all the guestbooks from the current site. The total attribute uses another service call to get the total number of guestbooks in the current site.

  • <liferay-ui:search-container-row> : determines the structure of each row of search container objects. You have to indicate the type of object in the list with the className attribute

    • row tag 내부에는 서로 다른 다 타입의 column tag도 설정한다

    • <liferay-ui:search-container-column-text property="name" \/> : first column 정의 (해석 : current guestbook object의 'name' text를 display하기 위해 선언)

    • <liferay-ui:search-container-column-jsp path="\/html\/guestbookadmin\/guestbook_actions.jsp" align="right" \/> : second column 정의 (해석 : displaying another JSP file within a search container column, path는 another JSP의 경로를 뜻함)

  • <liferay-ui:search-iterator> : actually iterating through and displaying the list of guestbooks

guestbook_actions.jsp 설명

<% 
String mvcPath = ParamUtil.getString(request, "mvcPath"); 
ResultRow row = (ResultRow) request .getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW); 
Guestbook guestbook = (Guestbook) row.getObject(); 
%>

-> In order to get the particular guestbook selected by the user, you have to use the search container result row selected by the user.

results matching ""

    No results matching ""