Last active
December 16, 2015 16:59
-
-
Save marsyang1/10f57ba6d3b88d9b7498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ManagedBean | |
@ViewScoped | |
public class FileUploadView { | |
public List<File> files = Lists.newArrayList(); | |
public void handleFileUpload(FileUploadEvent event) { | |
UploadedFile file = event.getFile(); | |
try { | |
String fileName = file.getFileName(); | |
String prefix = file.getFileName().substring(0, fileName.indexOf('.')); | |
String suffix = file.getFileName().substring(fileName.indexOf('.'), fileName.length()); | |
Path tempFile = Files.createTempFile(prefix, suffix); | |
tempFile = Files.write(tempFile, file.getContents(), StandardOpenOption.WRITE); | |
files.add(tempFile.toFile()); | |
Messages.addGlobalInfo("Succesful", event.getFile().getFileName() + " is uploaded."); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:h="http://java.sun.com/jsf/html" | |
xmlns:f="http://java.sun.com/jsf/core" | |
xmlns:p="http://primefaces.org/ui"> | |
<f:view contentType="text/html"> | |
<h:head> | |
<f:facet name="first"> | |
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/> | |
<title>PrimeFaces</title> | |
</f:facet> | |
</h:head> | |
<h:body> | |
<p:layout fullPage="true"> | |
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true"> | |
Header | |
</p:layoutUnit> | |
<p:layoutUnit position="south" size="100" closable="true" collapsible="true"> | |
Footer | |
</p:layoutUnit> | |
<p:layoutUnit position="west" size="175" header="Left" collapsible="true"> | |
<h:form> | |
<p:menu> | |
<p:submenu label="Resources"> | |
<p:menuitem value="Demo" url="http://www.primefaces.org/showcase-labs/ui/home.jsf"/> | |
<p:menuitem value="Documentation" url="http://www.primefaces.org/documentation.html"/> | |
<p:menuitem value="Forum" url="http://forum.primefaces.org/"/> | |
<p:menuitem value="Themes" url="http://www.primefaces.org/themes.html"/> | |
</p:submenu> | |
</p:menu> | |
</h:form> | |
</p:layoutUnit> | |
<p:layoutUnit position="center"> | |
Welcome to PrimeFaces | |
<p:growl id="messages" showDetail="true"/> | |
<p:commandButton type="button" onclick="PF('uploadDialog').show()"/> | |
<p:dialog id="uploadDialog" widgetVar="uploadDialog"> | |
<h:form> | |
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" | |
dragDropSupport="true" multiple="true" update="messages" fileLimit="3" | |
oncomplete="PF('uploadDialog').hide()"/> | |
</h:form> | |
</p:dialog> | |
<hr/> | |
<h:panelGrid columns="1" cellpadding="5"> | |
<p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();"/> | |
<p:commandButton value="Modal" type="button" onclick="PF('dlg2').show();"/> | |
<p:commandButton value="Effects" type="button" onclick="PF('dlg3').show();"/> | |
</h:panelGrid> | |
<p:dialog header="Basic Dialog" widgetVar="dlg1" minHeight="40"> | |
<h:outputText value="Resistance to PrimeFaces is futile!"/> | |
</p:dialog> | |
<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" height="100"> | |
<h:outputText value="This is a Modal Dialog."/> | |
</p:dialog> | |
<p:dialog header="Effects" widgetVar="dlg3" showEffect="explode" hideEffect="bounce" height="100"> | |
<h:outputText value="This dialog has nice effects."/> | |
</p:dialog> | |
</p:layoutUnit> | |
</p:layout> | |
</h:body> | |
</f:view> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment