ITPub博客

首页 > 应用开发 > IT综合 > SAP Hybris Commerce的JSP tag和SAP BSP tag的比较

SAP Hybris Commerce的JSP tag和SAP BSP tag的比较

原创 IT综合 作者:i042416 时间:2020-09-26 09:59:07 0 删除 编辑

Recently I am studying Hybrid Commerce and try to learn how the home page of Hybris storefront is implemented.



I try the approach introduced in my blog  Technical data for Hybris Commerce UI – how to find the name of JSP page for a given UI and find the JSP file which implements the home page:

hybris\bin\ext-template\yacceleratorstorefront\web\webroot\WEB-INF\views\responsive\pages\layout\landingLayout2Page.jsp

When I debug this file I find there are lots of usage of tag as displayed below.



Then I study this tag a little bit. In order to understand how it works, I have built a small example.

(1) Create a template.tag under folder WEB-INF/tags with the following source code:



<%@tag description="Jerry template" pageEncoding="UTF-8"%>  
<%@attribute name="headerarea" fragment="true" %>  
<%@attribute name="footerarea" fragment="true" %>  
<!DOCTYPE html>  <html>  
  <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  </head>  
  <body>  
    <jsp:invoke fragment="headerarea"/>  
    <br></br>
    <div style="color:blue;margin-left:30px;">Jerry: This paragraph is defined in the template!!</div>
    <jsp:doBody/>  
    <br></br>
    <jsp:invoke fragment="footerarea"/>  
  </body>  </html>

In this template I define two fragments with ID headerarea and footerarea, and in the middle of them I also hard coded a blue div.

(2) Create a JSP file which fills the actual content into the two fragments:

<%@page contentType="text/html" pageEncoding="UTF-8"%>  
<%@ taglib prefix="t" tagdir="/WEB-INF/tags/"%>  
<t:template>  
  <jsp:attribute name="headerarea">  
    Jerry: This is header area!  
  </jsp:attribute>  
  <jsp:attribute name="footerarea">  
    Jerry: This is footer area!  
  </jsp:attribute>  
  <jsp:body>  
    body area: Hello world!  
  </jsp:body>  </t:template>

And this is the final page displayed in browser:



And I also find the corresponding .java and compiled .class file under the work folder of my tomcat installation.



The fragment value filled in the JSP file could also be found here.



ABAP BSP

ABAP BSP(Business Server Page) has very similar name as JSP ( Java Server Page ), which indicates that it works the similar way under the hood: once a BSP page is accessed, an ABAP class is automatically generated ( if not existed yet ) to serve the page request. See one example below.


You can still open this generated class via SE24 as what you have done for normal class, except for the fact that it is not assigned to any package.



Based on this knowledge, I have also written a small tool to list all compiled ABAP classes and their corresponding BSP view name, which could act as a kind of BSP page browse history tool.

Just specify the user name and this report will list browse history:



REPORT ztool_display_page_name.PARAMETERS: name TYPE trdir-unam OBLIGATORY DEFAULT 'WANGJER'.DATA: lt_trdir TYPE STANDARD TABLE OF trdir,
      lt_page  TYPE STANDARD TABLE OF o2pagdir.TYPES: BEGIN OF ty_impl,
         name TYPE o2pagdir-implclass,
       END OF ty_impl.TYPES: tt_impl TYPE STANDARD TABLE OF ty_impl.START-OF-SELECTION.
  SELECT * INTO TABLE lt_trdir FROM trdir WHERE unam = name.
  IF sy-subrc <> 0 .
    WRITE: / 'No browse history found for current user'.
    RETURN.
  ENDIF.
  DATA: lt_impl  TYPE tt_impl,
        ls_trdir TYPE trdir,
        ls_impl  TYPE ty_impl.
  LOOP AT lt_trdir INTO ls_trdir.
    ls_impl-name = ls_trdir-name.
    APPEND ls_impl TO lt_impl.
  ENDLOOP.
  SELECT * INTO TABLE lt_page FROM o2pagdir FOR ALL ENTRIES IN lt_impl
    WHERE changedby = name AND implclass = lt_impl-name.
  SORT lt_page BY changedon DESCENDING.
  LOOP AT lt_page ASSIGNING FIELD-SYMBOL(<page>).
    WRITE: / <page>-implclass COLOR COL_GROUP, ' Last accessed on:', <page>-changedon COLOR COL_KEY,
    ' Component name: ' , <page>-applname+0(20) COLOR COL_NEGATIVE, ' view name: ', <page>-pagename+0(30) COLOR COL_POSITIVE.
  ENDLOOP.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24475491/viewspace-2724273/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
SAP成都研究院开发专家,SAP社区导师,SAP中国技术大使。

注册时间:2018-01-20

  • 博文量
    1820
  • 访问量
    811219