Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [JAVA, JSP e FTL/BSH]

  1. #1
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107

    [JAVA, JSP e FTL/BSH]

    Salve a tutti. Qualcuno di voi conosce la reale differenza ( a parte la netta separazione tra il mondo java e quello html ) tra lo scrivere le pagine in jsp puro oppure utilizzando la tecnica ftl appoggiandosi su dei file bsh? Quali sono i vantaggi di quest'ultima?
    Per essere + chiaro una pagina jsp è come se venisse spezzata in 2 mondi, uno contenente html e un altro java; vi posot un esempio:

    mondo html ( in un file di estensione .ftl )

    <div class='tabContainer'>
    Request
    Request Roles
    Request Items
    Item
    Notes
    Requirements
    Tasks
    </div>
    <TABLE border=0 width='100%' cellspacing='0' cellpadding='0' class='boxoutside'>
    <TR>
    <TD width='100%'>
    <table width='100%' border='0' cellspacing='0' cellpadding='0' class='boxtop'>
    <tr>
    <TD>
    <div class='boxhead'> Notes For Request Item: ${custRequestItem.description?if_exists}</div>
    </TD>
    <td align="right">
    <#if showAll = "false">
    [Show All Notes]
    <#else>
    [Show This Item's Notes]
    </#if>
    </td>
    </tr>
    </table>
    </TD>
    </TR>
    <TR>
    <TD width='100%'>
    <table width='100%' border='0' cellspacing='0' cellpadding='0' class='boxbottom'>
    <tr>
    <td>
    <#if notes?has_content>
    <table width="100%" border="0" cellpadding="1">
    <#list notes as noteRef>
    <tr>
    <td align="left" valign="top" width="35%">
    <div class="tabletext"> By: ${noteRef.firstName} ${noteRef.lastName}</div>
    <div class="tabletext"> At: ${noteRef.noteDateTime}</div>
    <#if showAll = "true">
    <div class="tabletext"> Item: ${noteRef.custRequestItemSeqId}</div>
    </#if>
    </td>
    <td align="left" valign="top" width="65%">
    <div class="tabletext">${noteRef.noteInfo}</div>
    </td>
    </tr>
    <#if noteRef_has_next>
    <tr><td colspan="2"><hr class="sepbar"></td></tr>
    </#if>
    </#list>
    </table>
    <#else>
    <div class="tabletext"> No notes for this request item.</div>
    </#if>
    </td>
    </tr>
    <tr>
    <td><hr class="sepbar"></td>
    </tr>
    <tr>
    <td>
    <form method="post" action="<@ofbizUrl>/createrequestitemnote</@ofbizUrl>" name="createnoteform">
    <input type="hidden" name="custRequestId" value="${custRequestId}">
    <input type="hidden" name="custRequestItemSeqId" value="${custRequestItemSeqId}">
    <table width="90%" border="0" cellpadding="2" cellspacing="0">
    <tr>
    <td width="26%" align='right'><div class="tableheadtext">New Note</div></td>
    <td width="74%">
    <textarea class="textAreaBox" name="note" rows="5" cols="70"></textarea>
    </td>
    <td></td>
    </tr>
    <tr>
    <td align="right">
    <input type="submit" style="font-size: small;" value="Create">
    </td>
    <td></td>
    </tr>
    </table>
    </form>

    </td>
    </tr>
    </table>
    </TD>
    </TR>
    </TABLE>


    Mondo java ( in un file .bsh )

    import java.util.*;
    import org.ofbiz.security.*;
    import org.ofbiz.entity.*;
    import org.ofbiz.base.util.*;
    import org.ofbiz.service.*;
    import org.ofbiz.workeffort.workeffort.*;

    delegator = request.getAttribute("delegator");

    String custRequestId = request.getParameter("custRequestId");
    String custRequestItemSeqId = request.getParameter("custRequestItemSeqId");
    String showAll = request.getParameter("showAll");
    if (showAll == null) showAll = "false";
    context.put("showAll",showAll);

    GenericValue custRequestItem = null;
    if (custRequestId != null && custRequestItemSeqId != null) {
    custRequestItem = delegator.findByPrimaryKey("CustRequestItem", UtilMisc.toMap("custRequestId", custRequestId, "custRequestItemSeqId", custRequestItemSeqId));
    if (custRequestItem != null) context.put("custRequestItem", custRequestItem);
    }

    Map fields = UtilMisc.toMap("custRequestId", custRequestId);
    if (showAll.equals("false")) fields.put("custRequestItemSeqId", custRequestItemSeqId);
    List notes = delegator.findByAnd("CustRequestItemNoteView", fields, UtilMisc.toList("-noteDateTime"));
    if (notes != null && notes.size() > 0) context.put("notes", notes);

    context.put("custRequestId",custRequestId);
    context.put("custRequestItemSeqId",custRequestItem SeqId);


    I due mondi sono messi in comunicazione attrverso un file .xml chiamato jpublish.xml che ha la seguente struttura:

    <?xml version="1.0"?>

    <jpublish>


    <page-root>WEB-INF/pagedefs</page-root>
    <template-root>templates</template-root>
    <action-root>WEB-INF/actions</action-root>


    <view-renderer classname="org.ofbiz.content.webapp.ftl.FreeMarker ViewRenderer"/>
    <page-renderer name="freemarker" classname="org.ofbiz.content.webapp.ftl.FreeMarker ViewRenderer"/>


    <repository name="pages" classname="org.jpublish.repository.filesystem.Exte ndedFileSystemRepository">
    <config-dir>WEB-INF/pagedefs</config-dir>
    <root>.</root>
    </repository>


    <character-encoding-map path="*">
    <page-encoding>UTF-8</page-encoding>
    <template-encoding>UTF-8</template-encoding>
    <request-encoding>UTF-8</request-encoding>
    <response-encoding>UTF-8</response-encoding>
    </character-encoding-map>


    <mime-mapping ext="txt" mimetype="text/plain"/>
    <mime-mapping ext="ftl" mimetype="text/html"/>
    <mime-mapping ext="htm" mimetype="text/html"/>
    <mime-mapping ext="html" mimetype="text/html"/>
    <mime-mapping ext="gif" mimetype="image/gif"/>
    <mime-mapping ext="jpg" mimetype="image/jpeg"/>
    <mime-mapping ext="jpeg" mimetype="image/jpeg"/>




    </jpublish>


    Qualcuno mi sa dire se questa tecnica, sebbene + ordinata almeno esteticamente, dovrebbe essere preferibile allo scrivere il file .jsp classico? Grazie e ciao
    Se vuoi trovare l'arcobaleno, devi sopportare la pioggia

  2. #2
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    Urp
    Se vuoi trovare l'arcobaleno, devi sopportare la pioggia

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.