Thursday 15 July 2010

How to save a image (mediumblob) in db with JSF? -


I have a few questions, I am trying to find a tutorial on how to image an image in a mailbox in my middle I want to save on JSF, primface (or if there is another way to do this), database and management bean, I want to do it without JSF and management bean, but since I am new to them, I am stuck on things ... I really am my There is no information about how to get an image from the SF page, changing it in a byte array and saving it. Please give any light.

I am sorry about what I have done here, but I'm really new, so please help me.

JSF Pages: - & gt; & Lt; P: show message id = "message" dipet = "true" auto-update = "true" off = "true" /> & lt; H: Panel Grid Column = "3" & gt; & Lt; H: outputtext value = "id:" /> & Lt; H: inputText id = "txtId" name = "txtId" value = "$ {produtoMB.prodAtual.id}" readonly = "true" /> & Lt; P: Message id = "txtId" for "A" /> & Lt; H: outputtext value = "photo:" /> & lt; P: fileUpload id = "txtFoto" name = "txtFoto" value = "$ {produtoMB.prodAtual.foto}" /> & Lt; P: for message id = "i" = "txtfoto" showSummary = "true" showDetail = "false" /> & Lt; H: panelGroup & gt; & Lt; H: command button name = "cmd" value = "insert" action = "$ {produtoMB.insert ()}" /> & Lt; / H: panelGroup & gt; & Lt; / H: panelGrid & gt; & Lt; / H: form & gt; & Lt; / H: Body & gt; & Lt; / Html & gt;

My entity

  @Entii public class executes the Produto Serializable {Personal Stable last long serial VERSIONUID = -8914597399554711634L; Private long ID; Private byte [] photo; @ ID @ Generated Values ​​Public Long (ICI) {return ID; } Public Zero Set ID (Long ID) {this.id = id; } @ Lab @ column (columnDefinition = "mediumblob") public byte [] getFoto () {Return photo; } Public Zero Setphoto (Byte [] Photo) {this.foto = foto; }}   

Managed Bean

  @ManagedBean @Session Public Classified ProdutoMB Apply Serializable {Personal Stable last long serialVersionUID = -3304202810037758438L; Private Produtual; Public ProdutoMB () {prodAtual = new Produto (); Prododo = new PrododaoImpl (); } Enter the public string () {try {prodDAO.insert (prodAtual); } Grip (SQLException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); } Return ""; }}   

Thanks!

Byte [] The picture is not available in the JSF page. Use the uploaded file in the Manage for Primase.

  & lt; P: fileUpload id = "txtFoto" name = "txtFoto" value = "$ {produtoMB.file}" />   

The uploaded file must be the property of Managed Bean. <@> @ManagedBean @Session Public Classified ProdutoMB implemented SerialJet {Private Uploaded File File; // save the use of inputstream and byte [] from file. }

Also define the file upload filter in web.xml

     

No comments:

Post a Comment