[RESOLVIDO] Não consigo fazer upload

Template

<?xml version="1.0" encoding="UTF-8"?>
<h:head>
    <h:outputStylesheet library="css" name="bootstrap.css" />
    <h:outputStylesheet library="css" name="estilo.css" />
    <h:outputScript library="js" name="jquery.mask.js" />
    <h:outputScript library="js" name="funcao.js" />

    <script>
        PrimeFaces.locales['pt'] = {
            closeText: 'Fechar',
            prevText: 'Anterior',
            nextText: 'Próximo',
            currentText: 'Começo',
            monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
            monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
            dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
            dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
            dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
            weekHeader: 'Semana',
            firstDay: 0,
            isRTL: false,
            showMonthAfterYear: false,
            yearSuffix: '',
            timeOnlyTitle: 'Só Horas',
            timeText: 'Tempo',
            hourText: 'Hora',
            minuteText: 'Minuto',
            secondText: 'Segundo',
            ampm: false,
            month: 'Mês',
            week: 'Semana',
            day: 'Dia',
            allDayText: 'Todo o Dia'
        };
    </script>


</h:head>

<h:body >
    <p:dialog widgetVar="dialogAguarde" header="Aguarde" 
              modal="true" closable="false" draggable="false"
              resizable="false">
        <div style="height: 100%;text-align: center;">
            <h:graphicImage id="imgAjax" library="img" name="ajax-loader.gif" />                    
        </div>
    </p:dialog>

    <p:ajaxStatus onstart="PF('dialogAguarde').show();" oncomplete="PF('dialogAguarde').hide();" />
    <p:growl autoUpdate="true" showDetail="true" life="5000" />

    <p:layout fullPage="true" >
        <p:layoutUnit position="center">
            <div style="overflow-x: hidden;">
                <ui:insert name="content" />
            </div>
        </p:layoutUnit>
    </p:layout> 
   
</h:body>

Upload xhtml

<?xml version='1.0' encoding='UTF-8' ?>

<ui:composition template="/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f=“http://xmlns.jcp.org/jsf/core”>
<ui:define name=“content” >
<h:head>
<h:outputStylesheet library=“css” name=“login.css” />
</h:head>
<h:body>

        <h:form>
            <h:form enctype="multipart/form-data">
                <h:inputFile value="#{uploadController.image}"/>
                <h:commandButton value="Upload" action="#{uploadController.doUpload()}">
                    <f:ajax execute="@form" render="@form"/>
                </h:commandButton>
            </h:form>
        </h:form>

    </h:body>
</ui:define>

</ui:composition>

upload bean

package br.com.credacif.bean;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.http.Part;
import javax.swing.filechooser.FileSystemView;

public class Upload {

private Part image;
private String filenameS;
private FileSystemView sistema;

public void doUpload(){
    try {
        InputStream in = image.getInputStream();
        
        sistema = FileSystemView.getFileSystemView();
        filenameS = sistema.getHomeDirectory().getPath() + File.separator + image.getSubmittedFileName();
        
        File f = new File(filenameS);
        
        f.createNewFile();
        FileOutputStream out = new FileOutputStream(f);
        
        byte[] buffer = new byte[1024];
        int length;
        
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }
        
        out.close();
        in.close();
        
    } catch(IOException e) {
        e.printStackTrace(System.out);
    }
}

public Part getImage() {
    return image;
}

public void setImage(Part image) {
    this.image = image;
}

public String getFilenameS() {
    return filenameS;
}

public void setFilenameS(String filenameS) {
    this.filenameS = filenameS;
}

public FileSystemView getSistema() {
    return sistema;
}

public void setSistema(FileSystemView sistema) {
    this.sistema = sistema;
}

}

ERRO:

/upload.xhtml @17,69 <h:inputFile> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: inputFile

Você está fazendo uma confusão enorme.
Não existe, mesmo, uma tag h:inputFile

Fonte

Por quê não usa o upload do primefaces? Creio que será bemmmmm mais fácil.

tem como mostrar um exemplo do primefaces?

Sim.
Veja

Obrigado

Usei o primefaces https://www.primefaces.org/showcase/ui/file/upload/basic.xhtml