JSF Best Practice
Das Verwenden von HTML-Code oder sonstigem Code (z.B. Java oder JSP-Tags) in einer JSF-Seite sollte soweit wie möglich vermieden werden. Hier ein weiniger gutes JSF-Beispiel:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Messages</title>
</head>
<body>
<f:view>
<h:form>
<h2>Message List</h2>
<h:outputText value="No messages to display" rendered="#{messageList.rowCount==0}"/>
<h:dataTable var="msg" value="#{messageList}" rendered="#{messageList.rowCount>0}">
<h:column>
<f:facet name="header">
<h:outputText value="Read"/>
</f:facet>
<h:selectBooleanCheckbox value="#{msg.read}" disabled="true"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Title"/>
</f:facet>
<h:commandLink value="#{msg.title}" action="#{messageManager.select}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date/Time"/>
</f:facet>
<h:outputText value="#{msg.datetime}">
<f:convertDateTime type="both" dateStyle="medium" timeStyle="short"/>
</h:outputText>
</h:column>
<h:column>
<h:commandButton value="Delete" action="#{messageManager.delete}"/>
</h:column>
</h:dataTable>
<h3><h:outputText value="#{message.title}"/></h3>
<div><h:outputText value="#{message.text}"/></div>
</h:form>
</f:view>
</body>
</html>
Wird in eine Seite HTML oder sostigen Fragmente eingebettet so wird:
-
das Paradigma Separation of Concern verletzt, -
die in der Spezfikation vorgesehene Markup-Unabhänigkeit nicht eingehalten, eine Starke Technologiebindung verursacht -In JSF sollten die Render-Klassen die Technologiebindung gekapselt herstelln,-
eine schlecht wartbare Anwendung mit niedriger Qualität erstellt, -
der Entwickler eher als Anfänger eingestuft.
Folgend eine besseres JSF Beispiel:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
version="1.2">
<jsp:directive.page contentType="text/html;charset=utf-8"/>
<f:view>
<af:pageTemplate
id="demoTemplate"
viewId="#{templates.componentTemplate}">
<f:attribute name="documentTitle" value="breadCrumbs Demo"/>
<f:attribute name="tagName" value="breadCrumbs"/>
<f:attribute name="visualDesignName" value=""/>
<f:attribute name="demoKind" value="component"/>
<f:facet name="center">
<af:panelGroupLayout layout="scroll">
<f:facet name="separator">
<af:separator/>
</f:facet>
<af:panelGroupLayout layout="vertical" inlineStyle="margin:0 10px 0 10px">
<af:breadCrumbs binding="#{editor.component}">
<af:commandNavigationItem text="Tag Guide" action="guide"/>
<af:commandNavigationItem text="Oracle.com" destination="http://www.oracle.com" targetFrame="_new"/>
<af:commandNavigationItem text="Disabled Item" disabled="true" action="guide.tree"/>
<af:commandNavigationItem text="NavigationPane Demo"
action="guide.navigationPane"/>
<af:commandNavigationItem text="Current Page" action="guide.breadCrumbs"/>
</af:breadCrumbs>
</af:panelGroupLayout>
<af:panelGroupLayout layout="vertical">
<af:outputText value="See also:"/>
<af:navigationPane hint="list">
<af:commandNavigationItem immediate="true" text="Page Hierarchy Demo"
action="guide.pageHierarchy"/>
<af:commandNavigationItem immediate="true" text="NavigationPane Demo"
action="guide.navigationPane"/>
<af:commandNavigationItem immediate="true" text="CommandNavigationItem Demo"
action="guide.commandNavigationItem"/>
</af:navigationPane>
</af:panelGroupLayout>
</af:panelGroupLayout>
</f:facet>
</af:pageTemplate>
</f:view>
</jsp:root>

Einen Kommentar schreiben
Sie müssen angemeldet sein, um kommentieren zu können.