webtier@glassfish.java.net

Re: JSF 2.0 Composite

From: <forums_at_java.net>
Date: Thu, 18 Nov 2010 00:11:44 -0800

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 &lsquo;resources/ezcomp/inputFile.xhtml&rsquo; 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
 


--
[Message sent by forum member 'josealvarezdelara']
View Post: http://forums.java.net/node/719408