Skip to main content

JSF 2.0 Composite components facet problem

3 replies [Last post]
toraage
Offline
Joined: 2010-11-17
Points: 0

Hi, I'm having some problems with passing a facet from one composite component to another. I have one page with a facet for a composite component, this compoiste component passes the facet along to another composite component. I can't get this to work. This don't seem to be a problem if the second component is a custom component.
Here's an example:
This page declare uses the composite component facletsProblemCC with a facet.
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:scomp="http://www.skd.no/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:scust="http://www.skd.no/jsf/custom">
<body>
<ui:component>
<h:form id="facletsProblem">
<h:outputText value="This is where the text should display:"></h:outputText>
<scomp:facletsProblemCC>
<f:facet name="facet">
<h:outputText value="Wow, it works!"/>
</f:facet>
</scomp:facletsProblemCC>
</h:form>
</ui:component>
</body>
</html>
This is the composite component that's passing along the facet to component facletsProblemCC2.
<?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:cc="http://java.sun.com/jsf/composite"
xmlns:scomp="http://www.skd.no/jsf/composite">
<body>

<cc:interface>
<cc:facet name="facet" />
</cc:interface>

<cc:implementation>
<scomp:facletsProblemCC2>
<cc:insertFacet name="facet" />
</scomp:facletsProblemCC2>
</cc:implementation>
</body>
</html>
This is the component displaying the facet:
<?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:cc="http://java.sun.com/jsf/composite">

<cc:interface>
<cc:facet name="facet" />
</cc:interface>

<cc:implementation>
<cc:renderFacet name="facet" />
</cc:implementation>
</html>
Regards
Tor Aage Ballo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
883 Guest
Offline
Joined: 2010-11-17
Points: 0

Hi, I'm having some problems with passing a facet from one composite
component to another. I have one page with a facet for a composite component,
this compoiste component passes the facet along to another composite
component. I can't get this to work. This don't seem to be a problem if the
second component is a custom component.

Here's an example:

This page declare uses the composite component facletsProblemCC with a facet.

/<?xml version="1.0" encoding="ISO-8859-1"?>

   
   
       
           
               
           
       
   

/

This is the composite component that's passing along the facet to component
facletsProblemCC2.

/<?xml version="1.0" encoding="ISO-8859-1"?>

   

   
       
   

/

This is the component displaying the facet:

/<?xml version="1.0" encoding="ISO-8859-1"?>

   

       

/

Regards

Tor Aage Ballo

josealvarezdelara
Offline
Joined: 2008-12-26
Points: 0

Hi Tor,

I have seen your post in the forum. It is really good.
Will you help me with my issue?

What I pretend is to convert a faces HtmlInputText in an html input type file.

This is the class that does it that,
<code>
@FacesComponent(value = "HtmlInputFile")
public class HtmlInputFile extends HtmlInputText {

// Getters ------------------------------------------------------------------------------------

@Override
public String getRendererType() {
return "javax.faces.File";
}

}
</code>
First I have defined a tag library,
<code>
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://balusc.net/jsf/html</namespace>
<tag>
<tag-name>inputFile</tag-name>
<component>
<component-type>HtmlInputFile</component-type>
</component>
</tag>
</facelet-taglib>
</code>

And over this I have created a composite component because it is the only way I can define a value attribute,
<code>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:bc="http://balusc.net/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite"
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">
<h:head>
<title>Esto no sale</title>
</h:head>
<h:body>
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="value" type="bean.Fichero" required="true" />
</composite:interface>

<!-- IMPLEMENTATION -->
<composite:implementation>
<bc:inputFile id="fileID" />
</composite:implementation>
</h:body>
</html>
</code>

It was created in a folder 'resources/ezcomp/inputFile.xhtml' of the project
so I call the composite component from the Jsf page as follows,
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
xmlns:p="http://primefaces.prime.com.tr/ui"
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="./css/default.css" rel="stylesheet" type="text/css" />
<title>Toma de Requisitos</title>
<p:resources />
</h:head>
<h:body>
<h:form id="formId" enctype="multipart/form-data">
<table align="center" width="65%" style="border: solid 1px #000000;">
<tr>
<td colspan="2" align="left"><h:outputText id="fecha" value="#{tomaRequisitosManagedBean.fecha}" /></td>
</tr>
<tr>
<td align="left">Welcome <h:outputText id="user" value="#{tomaRequisitosManagedBean.user}" /></td>
<td align="right"><h:outputText id="estado" value="#{tomaRequisitosManagedBean.estado}" /></td>
</tr>
</table>
<hr style="width: 65%; position: static" />
<table align="center" width="65%" style="border: solid 1px #000000;">
<tr>
<td>
<fieldset>
<legend>Mensajes</legend>
<table align="center" width="60%">
<tr>
<td witdth="70%">
<h:inputTextarea id="mensaje" value="#{tomaRequisitosManagedBean.mensaje}" cols="80" rows="2" />
</td>
<td width="30%"><h:commandButton id="enviar" value="Enviar" action="#{tomaRequisitosManagedBean.enviarMensaje}" /></td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
<hr style="width: 65%; position: static" />
<table align="center" width="65%" style="border: solid 1px #000000;">
<tr>
<td>
<fieldset>
<legend>Ficheros</legend>
<table align="center" width="60%">
<tr>
<td witdth="70%" rowspan="2">
<h:outputText value="#{tomaRequisitosManagedBean.mensaje}" />
</td>
</tr>
<tr>
<td><h:commandButton id="subir" value="Subir" action="#{tomaRequisitosManagedBean.enviarMensaje}" /></td>
<td><h:commandButton id="borrar" value="Borrar" action="#{tomaRequisitosManagedBean.enviarMensaje}" /></td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
<br/><br/>

<!- ****************************************************************** ->
<h:outputLabel for="file">File:</h:outputLabel>
<ez:inputFile id="file" value="#{fichero.path}" />
<h:commandButton value="Submit" action="#{tomaRequisitosManagedBean.submit}">
<f:attribute name="#{tomaRequisitosManagedBean.filePath}" value="#{fichero.path}" />
</h:commandButton>
<h:outputText value="File #{tomaRequisitosManagedBean.file.name} successfully uploaded!"
rendered="#{not empty tomaRequisitosManagedBean.file}" />
<!- ****************************************************************** ->

<h:messages />
</h:form>
</h:body>
</html>
</code>

Where the class Fichero is a session scope managed bean,
<code>
@ManagedBean
@SessionScoped
public class Fichero {

private String path;

/**
* @return the path
*/
public String getPath() {
System.out.println("Desde get: " + path);
return path;
}

/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
System.out.println("Desde set: " + path);
}

}
</code>

Well, the issue is that I cannot get and neither set the 'path' property that I want to pass
to my managed bean TomaRequisitosManagedBean that is the bean that do all the
process.

Do you see the problem? What am I doing wrong?

Any help will be appreciated.

Thanking in advance,
Jose

toraage
Offline
Joined: 2010-11-17
Points: 0

Hi Jose, I can't see what is the problem with your case, but would'nt it be better if you registred a separate post on this?

Regards
Tor Åge Ballo