Avatar billede fredand Forsker
12. februar 2003 - 11:52 Der er 6 kommentarer og
1 løsning

template.jsp in Suns Petstore??

Hello Amigos!

I'm looking at suns Petstore (for J2EE). They are in some how using a template.jsp thats looks like this:

<%@ taglib uri="/WEB-INF/template.tld" prefix="template" %>
<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
    <title><template:insert parameter="title" /></title>
</head>

<body bgcolor="#FFFFFF">
  <table width="100%" height="100%" border="0" cellpadding="5" cellspacing="0">
  <tr height="100" valign="top">
    <td colspan="3"><template:insert parameter="banner" /></td>
  </tr>
  <tr valign="top">
    <td width="20%" valign="top">Balle</td>
    <td width="60%" valign="top"><template:insert parameter="body" /></td>
    <td valign="top">
      Balle
    </td>
  </tr>
  <tr valign="bottom">
    <td colspan="3"><template:insert parameter="advicebanner" /></td>
  </tr>
  <tr>
    <td colspan="3"><template:insert parameter="footer" /></td>
  </tr>
  </table>
</body>
</html>

I guess that they insert some code at the tags :<template:insert parameter="xxx" />

And I also guess that they fetch the values to insert from a file called screendefinitions.xml. That file got tags that look like this:
  <template>/template.jsp</template>

  <screen>
    <screen-name>MAIN</screen-name>
    <parameter key="HtmlTitle" value="Welcome to Java Pet Store Demo" direct="true"/>
    <parameter key="HtmlBanner" value="/banner.jsp" direct="false"/>
    <parameter key="HtmlBody" value="/index.jsp" direct="false"/>
    <parameter key="HtmlPetFooter" value="/petfooter.jsp" direct="false"/>
    <parameter key="HtmlFooter" value="/footer.jsp" direct="false"/>
    <parameter key="Annotation" value="/estore/annotation/ann_overview_j2ee.jsp" direct="true"/>
  </screen>

...or...

  <default-template>/template.jsp</default-template>

  <screen name="main">
    <parameter key="title" value="Welcome to the BluePrints Petstore" direct="true"/>
    <parameter key="banner" value="/banner.jsp" />
    <parameter key="sidebar" value="/sidebar.jsp" />
    <parameter key="body" value="/main.jsp" />
    <parameter key="mylist" value="/mylist.jsp" />
    <parameter key="advicebanner" value="/advice_banner.jsp" />
    <parameter key="footer" value="/footer.jsp" />
  </screen>

But I can't figure out how or where they merge this together and how they sends the result back to the browser.

So if any one know the Petstore well, please let me know how it works with the template.jsp.

They also got a file called mappings.xml where they in some how mapps the incomming url to the outgoing. It has tags looking like this:
    <url-mapping url="order.do" screen="order_complete.screen" >
        <web-action-class>com.sun.j2ee.blueprints.petstore.controller.web.actions.OrderHTMLAction</web-action-class>
  </url-mapping>


But I can't figure out how this works together when I look at the code in the java-files.

So please help.

Best regards

Fredrik
Avatar billede disky Nybegynder
12. februar 2003 - 13:45 #1
the
<template:insert parameter="body" />
is a custom tag, which is sort of a method call down into a java class.

take a look at:
http://www.tek271.com/articles/JavaCustomTags.html

That is a good simple tutorial.
Avatar billede disky Nybegynder
12. februar 2003 - 13:46 #2
Avatar billede fredand Forsker
12. februar 2003 - 14:18 #3
Yes, that is right!

But how does the insert-tag get hold of the value , for eg. parameter="body", in the Petstore? Some where it must access the file screendefinitions.xml and get values form that file, but where????

Best regards
Fredrik
Avatar billede disky Nybegynder
12. februar 2003 - 14:30 #4
that is the job the java server does for you, you got some xml files defining your tags, and they 'point' to the java classes and methods, which are then called when the JSP pages is transformed into a .java file before compiling it. Or more correctly the tags are convertet into method call. (if i remember correctly)
Avatar billede fredand Forsker
12. februar 2003 - 15:54 #5
Hello Disky!

Yes thats right, but what I  am asking for is how the app Petstore works.

After I posted this question I have found out that the magic must be in the TemplateServlet in the Petstore. But I have not figure it out yet, how the TemplateServlet manage to extract the right values from the screendefinitions.xml, thats the question.

So if you know how the TempletServlet in the Petstore app works please let me know.

Best regards
Fredrik
Avatar billede disky Nybegynder
12. februar 2003 - 15:56 #6
I am pretty sure the documentation of either the PetStore or J2EE describes how it works.
Avatar billede fredand Forsker
18. februar 2003 - 11:26 #7
Hello Disky!

You were right, the online doc at Suns Petstore home page had a brief explanition about this.

Thanks for your help.

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester