Problem with accents when reloading form in JSF

0

I have an application that downloads a file with the filedownload component of primefaces, I had some problems but they were solved with help here, now I have another problem, the Download button is together with an Edit form, when the page is loaded, the fields are loaded well, when downloading the file, this makes the page and the fields update, but when doing this, it sends me a message saying that the format of some fields is not valid, Debugeando saw that when doing the update of the form, the fields that mark invalid are because they carry accents and are loading them with strange characters, but the first time they are loaded, the accents come out well.

Any ideas I could do?

Sorry, here the code, I did not have access to it until now, the problem is with the Download, when updating the form, the fields that have information and that carry accents, when updated, indicate that they do not have the valid format and leave them blank and when doing Debug, I see that he brings them with symbols

My XHTML

<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.org/ui" template="/WEB-INF/template.xhtml">

	<ui:define name="content">
		<div class="ui-g">
			<div class="ui-g-12">
				<div class="card centerText">

					<h:form id="formaUpdate" enctype="multipart/form-data">
					<p:growl id="growl" showDetail="true" sticky="true" />
					<h1>ACTUALIZAR RESGUARDO</h1>
					
					<input type="hidden" name="nombreUserLog" id="nombreUserLog" value="#{loginMB.nombre}" />
					
					<h:inputHidden id="idResguardo" value="#{resguardoMB.idResguardo}"/>
					<h:inputHidden id="rutaFormato" value="#{resguardoMB.rutaFormato}"/>
					<h:inputHidden id="nombreUserLogEdit" value="#{loginMB.nombre}"/>
					
					<p:panel header="Información del Equipo y Asignación">
					<p:panelGrid columns="4" layout="grid" style="width: 100%" cellpadding="5" styleClass="alignLeft">
					
						<h:outputLabel for="tipoResguardo" value="Tipo de Resguardo * " />
						<h:outputLabel for="numSerie" value="Número de Serie *" />
						<h:outputLabel for="marcaComputadora" value="Marca de Computadora *" />
						<h:outputLabel for="otraMarca" value="Otra Marca" />
												
						<p:selectOneMenu id="tipoResguardo" value="#{resguardoMB.tipoResguardo}">
							<f:selectItem itemLabel="#{resguardoMB.tipoResguardo}" itemValue=""/>
							<f:selectItem itemLabel="Usuario" itemValue="Usuario"/>
							<f:selectItem itemLabel="TI" itemValue="TI"/>
						</p:selectOneMenu>
						<p:inputText id="numSerie" required="true" value="#{resguardoMB.numSerie}"></p:inputText> 
						<p:selectOneMenu id="marcaComputadora" value="#{resguardoMB.marcaComputadora}">
							<f:selectItem itemValue="#{resguardoMB.marcaComputadora}" itemLabel="#{resguardoMB.marcaComputadora}" />
							<f:selectItems value="#{catcontenidoMB.catalogoMarcasComp}" var="marcas" itemValue="#{marcas.nombre}" itemLabel="#{marcas.descripcion}"/>
						</p:selectOneMenu>
						<p:inputText id="otraMarca" value="#{resguardoMB.otraMarca}"></p:inputText>
												
						<h:outputLabel for="sistemaOperativo" value="Sistema Operativo *" />
						<h:outputLabel></h:outputLabel>
						<h:outputLabel for="tipoComputadora" value="Tipo de Computadora *" />
						<h:outputLabel for="modeloComp" value="Modelo de Computadora *" />
												
						<p:selectOneMenu id="sistemaOperativo" value="#{resguardoMB.sistemaOperativo}">
							<f:selectItem itemValue="{resguardoMB.sistemaOperativo}" itemLabel="{resguardoMB.sistemaOperativo}" />
							<f:selectItems value="#{catcontenidoMB.catalogoSistOp}" var="sist" itemValue="#{sist.nombre}" itemLabel="#{sist.descripcion}"/>
						</p:selectOneMenu>
						<h:outputLabel></h:outputLabel>
						<p:selectOneMenu id="tipoComputadora" value="#{resguardoMB.tipoComputadora}">
							<f:selectItem itemValue="#{resguardoMB.tipoComputadora}" itemLabel="#{resguardoMB.tipoComputadora}" />
							<f:selectItems value="#{catcontenidoMB.catalogoTiposComp}" var="tipos" itemValue="#{tipos.nombre}" itemLabel="#{tipos.descripcion}"/>
						</p:selectOneMenu>
						<p:inputText id="modeloComp" required="true" value="#{resguardoMB.modeloComp}"></p:inputText>
												
						<h:outputLabel for="memoriaRam" value="Memoria RAM *" />
						<h:outputLabel for="valorCompra" value="Valor de Compra *" />
						<h:outputLabel for="userAsign" value="Staff Asignado *" />
						<h:outputLabel for="jefeUserAsign" value="Jefe Directo " />
												
						<p:inputText id="memoriaRam" required="true" value="#{resguardoMB.memoriaRam}"></p:inputText>
						<p:inputText id="valorCompra" required="true" value="#{resguardoMB.valorCompra}"></p:inputText>
						<p:selectOneMenu id="idUserAsign" value="#{resguardoMB.idUserAsign}">
							<f:selectItem itemValue="#{0}" itemLabel="#{resguardoMB.userAsign}" />
							<f:selectItems value="#{usersMB.usersList}" var="userasign" itemValue="#{userasign.id_users}" itemLabel="#{userasign.nombre}"/>
						</p:selectOneMenu>
						<p:selectOneMenu id="idJefeUserAsign" value="#{resguardoMB.idJefeUserAsign}">
							<f:selectItem itemValue="#{0}" itemLabel="#{resguardoMB.jefeUserAsign}" />
							<f:selectItems value="#{usersMB.usersList}" var="jefe" itemValue="#{jefe.id_users}" itemLabel="#{jefe.nombre}"/>
						</p:selectOneMenu>
						
						<h:outputLabel for="ubicacionUserAsign" value="Ubicación " />
						<h:outputLabel for="fechaAsignacion" value="Fecha de Asignación " />
						<h:outputLabel for="motivoAsignacion" value="Motivo de Asignación *" />
						<h:outputLabel></h:outputLabel>
						
						<p:selectOneMenu id="ubicacionUserAsign" value="#{resguardoMB.ubicacionUserAsign}" escape="false" >
							<f:selectItem itemValue="#{resguardoMB.ubicacionUserAsign}" itemLabel="#{resguardoMB.ubicacionUserAsign}" />
							<f:selectItems value="#{catcontenidoMB.catalogoUbicaciones}"
								var="ubic" itemValue="#{ubic.nombre}"
								itemLabel="#{ubic.descripcion}" />
						</p:selectOneMenu>
						<p:calendar id="fechaAsignacion" value="#{resguardoMB.fechaAsignacion}" pattern="dd-MM-yyyy" mask="true" />
						<p:selectOneMenu id="motivoAsignacion" value="#{resguardoMB.motivoAsignacion}" >
							<f:selectItem itemValue="#{resguardoMB.motivoAsignacion}" itemLabel="#{resguardoMB.motivoAsignacion}" />
							<f:selectItems value="#{catcontenidoMB.catalogoMotivAsign}" var="motiv" itemValue="#{motiv.nombre}" itemLabel="#{motiv.descripcion}"/>
						</p:selectOneMenu>
						<h:outputLabel></h:outputLabel>
						
					</p:panelGrid>
					</p:panel>
					
					<p:panel header="Adicionales">
					<p:panelGrid columns="4" layout="grid" style="width: 100%" cellpadding="5" styleClass="alignLeft">
											
						<p:inputTextarea id="comentarios" rows="5" cols="30" value="#{resguardoMB.comentarios}" counter="contador" maxlength="150" counterTemplate="{0} caracteres restantes. " autoResize="false" />
    					<p:commandButton value="ACTUALIZAR" action="#{resguardoMB.updateResguardo}" update="growl"></p:commandButton>
    					<p:commandButton rendered="#{loginMB.resguardo_rol eq ('SUPERADMIN' or 'ADMIN')}" value="DESCARGAR ARCHIVO" actionListener="#{resguardoMB.descargarFormato}" onclick="PrimeFaces.monitorDownload(start, stop);" update="@form">
						<p:fileDownload value="#{resguardoMB.archivoDescarga}" />
					</p:commandButton>
						<p:button value="INICIO" outcome="index"></p:button>
    																	
    					<h:outputText id="contador" /> 
    					<h:outputLabel></h:outputLabel>
						<h:outputLabel></h:outputLabel>
						<h:outputLabel></h:outputLabel>
						
					</p:panelGrid>
    					<p:fileUpload id="archivoFormato" rendered="#{loginMB.resguardo_rol eq ('SUPERADMIN' or 'ADMIN')}" fileUploadListener="#{resguardoMB.handleFileUpload}" mode="advanced" update="growl" multiple="false"
			                sizeLimit="1048576"
			                allowTypes="/(\.|\/)(pdf)$/"
			                uploadLabel="Cargar" cancelLabel="Cancelar" label="Buscar archivo"/>
			            <h:outputLabel></h:outputLabel> 
					</p:panel>
					</h:form>

				</div>
			</div>
		</div>
		
		<script type="text/javascript">
		function start() {
		    PF('statusDialog').show();
		}
		 
		function stop() {
		    PF('statusDialog').hide();
		}
		</script>

	</ui:define>

</ui:composition>

My Managed Bean

public void descargarFormato() throws Exception {

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    String rutaFormatoasign = ec.getRequestParameterMap().get("formaUpdate:rutaFormato");

    File origen = new File(rutaFormatoasign);
    String nombre = origen.getName();
    File destino = new File("C:/Program Files/Apache Software Foundation/Tomcat 8.0/webapps/ResguardosLat-1.0/resources/" + "archivoDescarga.pdf");

    try {
            InputStream in = new FileInputStream(origen);
            OutputStream out = new FileOutputStream(destino);

            byte[] buf = new byte[1024];
            int len;

            while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
            }

            in.close();
            out.close();
    } catch (IOException ioe){
            ioe.printStackTrace();
    }
    rutaFormato = rutaFormatoasign;
    InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/resources/" + "archivoDescarga.pdf");
    setArchivoDescarga(new DefaultStreamedContent(stream, "application/pdf", nombre));
}

Thanks to everyone

    
asked by Jorge Alberto López Zamarripa 17.01.2018 в 06:58
source

1 answer

0

It was already solved, in case someone has the same problem, the root of it is in the Ajax calls, when the refresh is made it takes what is in the form, but it takes it as HTML input.

The solution is to create a Filter to force the UTF in the request, in this post there is the solution

link

Greetings

    
answered by 19.01.2018 / 23:03
source