Hi,
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">
<!-
****************************************************************** ->
<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/717560