PV230 - cvičení 3 - příklady + postup PV230 - cvičení 3 Resource serving Statický obsah (obrázky) Do view.jsp přidat a upravit následující řádky ... var "detailIconURL" "<%=ICON_DETAIL %>" "cacheLevelFull" <%-- pridat --%> var "product" "${products}"
<%-- upravit"${product.name}" "${detailIconURL}" "detail" --%>
... Do CatalogConstants přidat public ICON_DETAIL = ;static final String "/img/detail.png" Dynamický obsah Do view.jsp přidat var "queryURL" "<%= RESOURCE_QUERY %>" ... <%-- upravit --%>"text" "<%= PARAM_QUERY %>" "${ns}query" "off" V CatalogPorltet přidat @Override void serveResource(ResourceRequest request, ResourceResponse response)public throws PortletException, IOException { resourceID = request.getResourceID();String (RESOURCE_QUERY.equals(resourceID)) {if serveAutocompleteQuery(request, response); } {else .serveResource(request, response);super } } void serveAutocompleteQuery(ResourceRequest request, ResourceResponse response)private throws IOException { searchString = request.getParameter(PARAM_AUTOCOMPLETE_QUERY);String (searchString == ) {if null ;return } PrintWriter out = ;null {try response.setContentType( );"text/plain" out = response.getWriter(); (ProductDTO p : ServiceProvider.getCatalog().findProducts(searchString)) {for out.println(p.getName()); } } (IOException ex) {catch // log error } {finally out.close(); } } Do CatalogConstants přidat public PARAM_AUTOCOMPLETE_QUERY = ;static final String "q" RESOURCE_QUERY = ;public static final String "query" Meziportletová komunikace - veřejné parametry Vytvoříme portlet Detail, který bude zobrazovat podrobné informace o produktu. Vytvoříme package eu.ibacz.pv230.simpleshop.portlet.detail a v něm třídy DetailPortlet a DetailConstants. DetailPortlet @Override void doView(RenderRequest request, RenderResponse response) PortletException,protected throws IOException { productId = request.getParameter(PARAM_PRODUCT_ID);String (productId != ) {if null id = .parseLong(productId);long Long request.setAttribute(ATTRIBUTE_PRODUCT, ServiceProvider.getCatalog().getProductById(id)); } PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(JSP_VIEW); dispatcher.include(request, response); } DetailConstants public class DetailConstants SimpleShopConstants {extends JSP_VIEW = ;public static final String "/WEB-INF/jsp/detail/view.jsp" } Vytvoříme složku /WEB-INF/jsp/detail a v ní jsp stránku s následujícím obsahem <%@include file= %>"../init.jspf" "content.detail" <%@page = %>import " eu.ibacz.pv230.simpleshop.portlet.detail.DetailConstants.*"static
"${ns}detailView"

"ss-msg-product-detail" "${product != }"null
"label" "ss-msg-name" "${product.name}"
"label" "ss-msg-description" "${product.description}"
"label" "ss-msg-price" "${product.price}"
"ss-msg-no-product-selected"
Vytvoříme properties soubor detail ve složce content s následujícími klíči javax.portlet.title=Detail ss-msg-product-detail=Product detail ss-msg-name=Name ss-msg-description=Description ss-msg-price=Price ss-msg-no-product-selected=No product selected. V portlet.xml přidat Detail portlet a public render parametr Catalog eu.ibacz.pv230.simpleshop.portlet.catalog.CatalogPortlet text/html view en cs content.catalog productIdpublic public Detail eu.ibacz.pv230.simpleshop.portlet.detail.DetailPortlet text/html view en cs content.detail productIdpublic public < -namespace>http:default //pv230.ibacz.eu/cv3default < -render-parameter>public productId productId public Do liferay-portlet.xml Detail true Do liferay-display.xml "Detail" Do catalog/view.jsp přidat var "showDetailURL" "<%= PARAM_PRODUCT_ID %>" "${product.id}" "${showDetailURL}"
"${product.name}" "${detailIconURL}" "detail"