FileUpload PrimeFaces 5.1
Java





2.497 visualizaciones desde el 30 de Marzo del 2016
Les dejo en ejemplo de como se sube una imagen a una ruta del server en especifico, el ejemplo esta echo con Primefaces 5.1 y Maven 3.3 espero y les guste. Saludos






/**
* Place the JFrame with the parameters by moving the component relative to the center of the screen.
* Colocamos el JFrame con los parámetros desplazando el componente respecto al centro de la pantalla.
* @param moveWidth int positive or negative offset width (desplazamiente de width positivo o negativo).
* @param moveHeight int Positive or negative offset height (desplazamiento de height positivo o negativo).
*/
public void setLocationMove(int moveWidth, int moveHeight) {
// Obtenemos el tamaño de la pantalla.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Obtenemos el tamaño de nuestro frame.
Dimension frameSize = this.getSize();
frameSize.width = frameSize.width > screenSize.width?screenSize.width:frameSize.width;
frameSize.height = frameSize.height > screenSize.height?screenSize.height:frameSize.height;
// We define the location. Definimos la localización.
setLocation((screenSize.width - frameSize.width) / 2 + moveWidth, (screenSize.height - frameSize.height) / 2 + moveHeight);
}
/**
* Set the JFrame in the center of the screen.
* Colocamos nuestro JFrame en el centro de la pantalla.
*/
public void setLocationCenter(){
setLocationMove(0, 0);
}
new JFrameCenterSimple(100, 200).setVisible(true);
new JFrameCenterSimple(-100, -200).setVisible(true);
new JFrameCenterSimple().setVisible(true);
/**
* Standard method to print a JTable to the printer directly..
* Método estándar para imprimir un JTable por la impresora directamente.
* <h3>Example (Ejemplo)</h3>
* <pre>
* utilJTablePrint(jTable2, getTitle(), "Código Xules", true);
* </pre>
*
* @param jTable <code>JTable</code>
* the JTable we are going to extract to excel
* El Jtable que vamos a extraer a excel.
* @param header <code>String</code>
* Header to print in the document.
* Cabecera que imprimiremos en el documento.
* @param footer <code>String</code>
* Footer to print in the document.
* Pie de página que imprimiremos en el documento.
* @param showPrintDialog <code>boolean</code>
* To show or not the print dialog.
* Mostramos o no el diálogo de impresión.
*/
public void utilJTablePrint(JTable jTable, String header, String footer, boolean showPrintDialog){
boolean fitWidth = true;
boolean interactive = true;
// We define the print mode (Definimos el modo de impresión)
JTable.PrintMode mode = fitWidth ? JTable.PrintMode.FIT_WIDTH : JTable.PrintMode.NORMAL;
try {
// Print the table (Imprimo la tabla)
boolean complete = jTable.print(mode,
new MessageFormat(header),
new MessageFormat(footer),
showPrintDialog,
null,
interactive);
if (complete) {
// Mostramos el mensaje de impresión existosa
JOptionPane.showMessageDialog(jTable,
"Print complete (Impresión completa)",
"Print result (Resultado de la impresión)",
JOptionPane.INFORMATION_MESSAGE);
} else {
// Mostramos un mensaje indicando que la impresión fue cancelada
JOptionPane.showMessageDialog(jTable,
"Print canceled (Impresión cancelada)",
"Print result (Resultado de la impresión)",
JOptionPane.WARNING_MESSAGE);
}
} catch (PrinterException pe) {
JOptionPane.showMessageDialog(jTable,
"Print fail (Fallo de impresión): " + pe.getMessage(),
"Print result (Resultado de la impresión)",
JOptionPane.ERROR_MESSAGE);
}
}