Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    643

    [JSF] Perchè non mi inserisce i contenuti definiti?

    Ciao,
    è la prima volta che uso JSF e stò avendo qualche problemino...

    Ho questo file chiamato view.xhtml: nel file DEFINISCO il contenuto di alcune aree che verranno inserite nel template fids-template.xhtml (e ciò funziona senza problemi)

    codice:
    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    	    		xmlns:ui="http://java.sun.com/jsf/facelets"
    	  			xmlns:h="http://java.sun.com/jsf/html"
    	  			xmlns:f="http://java.sun.com/jsf/core"
    	  			xmlns:p="http://primefaces.prime.com.tr/ui"
    				template="/WEB-INF/layouts/fids-template.xhtml">
    
    <ui:define name="title">Ajax With PrimeFaces CommandButton</ui:define>
    
    <ui:define name="notes">
    	<h5>Files to review:</h5>
    	
    
    
    	  	Flow definition and view.xhtml in <span class="alt">src/main/webapp/WEB-INF/flows/ajax-primefaces</span>
    
    	  	Java class <span class="alt">~/ajax/UserBean.java</span>
    	</p>
    	<hr/>
    </ui:define>
    
    
    <ui:define name="content">
    	
    	<p:layout style="width:600px;height:400px">
    		<p:layoutUnit position="left" width="200">
    			<ui:insert name="rightPanel"/>
    		</p:layoutUnit>
    		
    		<p:layoutUnit position="center">
    			<ui:insert name="centertPanel"/>
    		</p:layoutUnit>
    	</p:layout>
    	
    </ui:define>
    
    </ui:composition>
    Il problema nasce nella definizione del contenuto dell'area etichettata come "contente"
    In quest'area gli dico di inserire della roba che definisco in un altro file tramite i 2 tag:
    <ui:insert name="rightPanel"/> e <ui:insert name="centertPanel"/>

    Definisco allora un altro file che chiamo panelContent.xhtml e che conterrà appunto il contenuto da inserire quà dentro:

    codice:
    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    	    		xmlns:ui="http://java.sun.com/jsf/facelets"
    	  			xmlns:h="http://java.sun.com/jsf/html"
    	  			xmlns:f="http://java.sun.com/jsf/core"
    	  			xmlns:p="http://primefaces.prime.com.tr/ui"
    				template="/WEB-INF/flows/secured/sReparti/view.xhtml">
    				
    	<ui:define name="rightPanel">
    		
    
    TEST</p>
    	</ui:define>
    	
    	<ui:define name="centertPanel">
    		
    
    TEST</p>
    	</ui:define>
    				
    </ui:composition>
    Come potete vedere gli dico che il template è il file view.xhtml (che credo significhi che deve andare ad inserire là dentro la roba che definisco nel file) e poi gli metto i 2 tag define con i nomi delle aree dove inserire il contenuto...

    Solo che quando apro la pagina...mi si visualizza tutto tranne questi valori (l'otput TEST)
    Come mai? cosa sbaglio?

    Grazie
    Andrea

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    643
    up :-(

  3. #3
    Se magari ci fai vedere il template riusciamo a capirlo....

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    643
    Originariamente inviato da francesco.muia
    Se magari ci fai vedere il template riusciamo a capirlo....
    Ok,
    allora ti faccio vedere tutto così si evitano incomprensioni:

    1) Il template base dove definisco le varie aree è fids-template-base.xhtml ed ha il seguente codice:
    codice:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    	xmlns:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:c="http://java.sun.com/jsp/jstl/core"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:sec="http://www.springframework.org/security/tags"
    	xmlns:p="http://primefaces.prime.com.tr/ui">
    <f:view encoding="ISO-8859-1" contentType="text/html">
    <h:head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<title>WebFids - Intranet Management System v1.0</title>
    	<link rel="stylesheet" href="${request.contextPath}/app/resources/styles/blueprint/screen.css" type="text/css" media="screen, projection" />
    	<link rel="stylesheet" href="${request.contextPath}/app/resources/styles/blueprint/print.css" type="text/css" media="print" />
    	<!--[if lt IE 8]>
    		<link rel="stylesheet" href="${request.servletPath}/styles/blueprint/ie.css" type="text/css" media="screen, projection" />
    	<![endif]-->
    	<ui:insert name="headIncludes"/>
    	<style type="text/css">
    
    	<!--
    
    	body { 	background:#efefef url(${request.contextPath}/app/resources/images/bg-gray.png) center top repeat-y }
    
    	.overtopLogs{	height:120px;
    					margin-top:10px;
    					background:#ffffff url(${request.contextPath}/app/resources/images/logo-bar-bg.png) left top no-repeat}
    					
    					
    	.ui-widget, ui-widget .ui-widget {
    		font-size:98% !important;
    	}
    	
    	table, caption, tbody, tfoot, thead, tr, th, td {
    	  margin: 0;
    	  padding: 0;
    	  border: 0;
    	  font-weight: inherit;
    	  font-style: inherit;
    	  font-size: 100%;
    	  font-family: inherit;
    	  vertical-align: baseline;
    	}
    	
    	/* Tables still need 'cellspacing="0"' in the markup. */
    table { border-collapse: separate; border-spacing: 0; }
    caption, th, td { text-align: left; font-weight: normal; }
    table, td, th { vertical-align: middle; }
    	
    	//-->
    
    	</style>
    	<ui:insert src="procSripts" />
    </h:head>
    <h:body>
    <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>          
    <p:dialog modal="true" widgetVar="statusDialog" header="Status"   
            draggable="false" closable="false">  
        <p:graphicImage value="/images/ajaxloadingbar.gif" />  
    </p:dialog> 
    	<div class="container">
    		<div> 
    			<div class="overtopLogs" align="right">
    				<div style="width:280px">
    					<sec:authorize ifNotGranted="ROLE_USER">
    					<form name="f" action="${request.contextPath}/app/j_spring_security_check" method="post">
    						<p:panel header="Login Information" style="font-size:95% !important; height: 100px;">
    							<table style="width:100%; border: 0;">
    								<tbody>
    									<tr>
    										<td style="width: 100px; text-align: right; margin: 4px; padding: 4px;"><h:outputLabel value="User:" /></td>
    										<td><c:if test="${not empty param.login_error}">
    												<c:set var="username" value="${sessionScope.SPRING_SECURITY_LAST_USERNAME}"/>
    											</c:if><input type="text" name="j_username" value="#{username}" /></td>
    									</tr>
    									<tr>
    										<td style="text-align: right; margin: 4px; padding: 4px;"><h:outputLabel value="Password: " /></td>
    										<td><input type="password" name="j_password" /></td>
    										<td style="text-align: left;"><input name="submit" type="submit" value="Login" /></td>
    									</tr>
    								</tbody>
    							</table>
    						</p:panel>
    					</form>
    				</sec:authorize>
    				
    				<sec:authorize ifAnyGranted="ROLE_USER">
    					<p:panel header="User Information" style="font-size:95% !important; height: 100px;">
    							<table style="width:100%; margin: 4px; padding: 4px; border: 0;">
    								<tbody>
    									<tr>
    										<td>[img]#{request.contextPath}/app/resources/images/header_account.gif[/img]</td>
    										<td style="text-align: left;">User: ${currentUser.name}</td>
    									</tr>
    								</tbody>
    							</table>
    						</p:panel>
    				</sec:authorize>
    				</div>
    			</div>
    			<sec:authorize ifAnyGranted="ROLE_USER">
    				<div><ui:insert name="navBar" /></div>
    			</sec:authorize>
    			<p:spacer height="10" />
    			<div><ui:insert name="title"/><div>
    				<h2>WebFids - Intranet Management System v1.0.</h2>
    			</div></div>
    			
    			<div><ui:insert name="notes"/></div>
    	
    			<sec:authorize ifAnyGranted="ROLE_USER">
    				<div><ui:insert name="content"/></div>
    			</sec:authorize>
    		</div>
    	</div>
    </h:body>
    </f:view>
    Poi c'è il file file fids-template.xhtml che come puoi vedere DEFINISCE l'elemento "navBar" che viene inserito nel file fids.template-base.xhtml (credo che ciò sia detto dal fatto che ho la riga di codice: template="/WEB-INF/layouts/fids-template-base.xhtml">, giusto?)
    codice:
    
    3) A questo punto ho il file view.xhtml che definisce il contenuto di altre aree (come l'area content):
    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns="http://primefaces.prime.com.tr/ui"
    template="/WEB-INF/layouts/fids-template.xhtml">

    <ui:define name="notes"><h3 class="alt">Benvenuto utente #{currentUser.name}!</h3></ui:define>

    <ui:define name="content">

    <ui:insert name="testo">
    Nessun testo inserito
    </ui:insert>

    </ui:define>

    </ui:composition>
    [/code]

    Ora vediamo se ho capito bene la logica (prima di oggi non ho mai usato la ui:composition)
    In questo file lui prende come template il file fids-template.xhtml che definiva l'area navBar per il file fids-template-base.xhtml...quindi il contenuto dell'area content è come se andasse inserito nel tag <ui:insert di fids-template-base.xhtml? è giusto come ragionamento?

    Fin quì però non ho problemi...il vero problema nasce dal fatto che ho l'esigenza di specificare una nuova area chiamata "testo" dentro il file view.xhtml

    Allora che faccio, seguendo sempre la stessa logica uso il tag <ui:insert name="test">

    e poi creo un'altro file chiamato valori.xhtml che contiene la DEFINIZIONE dei contenuti da inserire in tale area. Questo è il codice del mio file valori.xhtml (che come template ha view.xhtml):

    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    	xmlns:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:p="http://primefaces.prime.com.tr/ui"
    	template="/WEB-INF/flows/secured/sReparti/view.xhtml">
    	
    	<ui:define name="testo">
    		
    
    VALORI INSERITI !!!</p>
    	</ui:define>
    	
    </ui:composition>
    Non riesco proprio a capire cosa ci sia che non và...cosa mi sfugge?

    Grazie
    Andrea

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 © 2024 vBulletin Solutions, Inc. All rights reserved.