بتاريخ: 28 أغسطس 201213 سنة comment_226982 السلام عليكمعندى شاشة فيها بيانات الموظف فيها ايضا صورة الموظفاريد ان اجعل المستخدم يختار الصورة من على جهازه ثم يقوم النظام بتحميلها على السرفر فى مجلد خاص به صور الموظفينقمت بعمل التالي1- استخدمت af:inputFile كالتالي <af:inputFile id="if1" label="#{viewcontrollerBundle.UPLOAD_PHOTO_FOR} #{bindings.EmpNum}" value="#{backingBeanScope.basicInfo.file}" autoSubmit="true"/> و بالطبع عملت bean و وضغتها فى ال backingBeanScope2- كتبت فى الكلاس الكود التالي import java.awt.image.BufferedImage; import java.io.File; import java.io.InputStream; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.imageio.ImageIO; import javax.servlet.ServletContext; import oracle.adf.model.BindingContext; import oracle.adf.model.binding.DCBindingContainer; import oracle.adf.model.binding.DCIteratorBinding; import oracle.binding.AttributeBinding; import oracle.binding.BindingContainer; import oracle.binding.OperationBinding; import oracle.jbo.Row; import org.apache.myfaces.trinidad.model.UploadedFile; import oracle.jbo.domain.Number; public class BasicInfo { private UploadedFile _file; public UploadedFile getFile() { return _file; } public void setFile(UploadedFile file) { _file = file; } public String processUpload() { UploadedFile myfile = this.getFile(); FacesContext fctx = FacesContext.getCurrentInstance(); ServletContext servletCtx = (ServletContext)fctx.getExternalContext().getContext(); String imageDirPath = servletCtx.getRealPath("/"); try { InputStream inputStream = myfile.getInputStream(); BufferedImage input = ImageIO.read(inputStream); File outputFile = new File(imageDirPath + "/images/" + this.getCurrentEmployeeId()+".png"); ImageIO.write(input, "PNG", outputFile); } catch (Exception ex) { // handle exception } FacesMessage message = new FacesMessage("Successfully uploaded file " + myfile.getFilename() + " (" + myfile.getLength() + " bytes)"); fctx.addMessage(null, message); return null; } public Number getCurrentEmployeeId(){ BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("EmpNum"); return (Number)attr.getInputValue(); } 3- قمت باضافة command button على الصفحة كالتالي <af:commandButton text="#{viewcontrollerBundle.PROCESS}" id="cb1" action="#{backingBeanScope.basicInfo.processUpload}"/> 4- فى ال af:form قمت بتغير قيمة useUpload = true <af:form id="f1" usesUpload="true"> 5- , hodvh tn lgt صثلامخلهؤزءةم rlj fhgju]dg hgjhgd <native-io-enabled>true</native-io-enabled> <show-archived-real-path-enabled>true</show-archived-real-path-enabled> الوقتى لما بجرب اشغل الصفحة بختار الصورة عادى لكن اول لما بضغط على الزر process اللى هو بينقل الصورة على السيرفر بيظهر الخطا دة javax.faces.el.EvaluationException: java.lang.NullPointerException <LifecycleImpl> <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase INVOKE_APPLICATION 5 javax.faces.FacesException: #{backingBeanScope.basicInfo.processUpload}: java.lang.NullPointerException لما جيت اعمل debug لاحظت ان بعد ما اعدى السطر دة UploadedFile myfile = this.getFile();الاقى ان المتغير myfile لسة قيمتة ب nullمش عارف لي بيجى ب null يا ريت لو فى حد عندة مثال جاهز و مجربة يرفعة على المنتدىشكرا تقديم بلاغ
بتاريخ: 3 سبتمبر 201213 سنة comment_227128 سلامجربت نفس الطريفه و لم تنجح معي و عندما حددت المسار لم تنجح معي getCurrentImageid() تقديم بلاغ
بتاريخ: 4 سبتمبر 201213 سنة comment_227163 ضع partialTriggers للزر بحيث يحتوي على id الـ inputFile تقديم بلاغ
بتاريخ: 10 سبتمبر 201213 سنة comment_227291 String imageDirPath = servletCtx.getRealPath("/"); . . . new File(imageDirPath + "/images/" + this.getCurrentEmployeeId()+".png"); وضعت مجلد اسمه image في C:\JDeveloper\mywork\Application5\ViewController\public_html\images و لكني لا اجد الصور كيف و اين اعرف مجلد الصور تقديم بلاغ
بتاريخ: 29 أكتوبر 201213 سنة comment_228472 Dearas per my knowledge, using project internal directory to save employees images is a big false, as u will loose all images in 2nd deployment so please use external directory and use a servlet to access otherwise use the BlobDomain solution to save in db blob column in Employee tablethanks تقديم بلاغ
بتاريخ: 30 أكتوبر 201213 سنة كاتب الموضوع comment_228506 use external directory and use a servlet to accessthanks Thank you for you recommendation . Do you have example about how to use servlet to access external directory? تم تعديل 30 أكتوبر 201213 سنة بواسطة tarek_fathi تقديم بلاغ
بتاريخ: 31 أكتوبر 201213 سنة comment_228547 Dear Tarek kindly use this one and please put these tages in your web.xml file (please note , i use/mnt/images as i have my stand aline wls in Linux platform) <context-param> <description>Directory of the image storage of the application</description> <param-name>imageDirectory</param-name> <param-value>/mnt/images</param-value> </context-param> <servlet> <servlet-name>ImageServlet</servlet-name> <servlet-class>Interface.backing.ImageServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ImageServlet</servlet-name> <url-pattern>/imagestorage/*</url-pattern> </servlet-mapping> -------------------------------------------------------------------- package Interface.backing; import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.Closeable;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.net.URLDecoder;import javax.servlet.ServletConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class ImageServlet extends HttpServlet {ServletConfig config;// Constants --------------------------------------------------------------------------------// 10KB.private static final int DEFAULT_BUFFER_SIZE = 10240;// Properties --------------------------------------------------------------------------------private String imagePath;// Actions --------------------------------------------------------------------------------public void init(ServletConfig config) throws ServletException {this.config = config;ServletContext application = config.getServletContext();this.imagePath = application.getInitParameter("imageDirectory");super.init(config);}protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {String requestedImage = request.getPathInfo();if (requestedImage == null) {response.sendError(HttpServletResponse.SC_NOT_FOUND);return;}File image =new File(imagePath, URLDecoder.decode(requestedImage, "UTF-8"));if (!image.exists()) {response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.return;}String contentType = getServletContext().getMimeType(image.getName());if (contentType == null || !contentType.startsWith("image")) {response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.return;}response.reset();response.setBufferSize(DEFAULT_BUFFER_SIZE);response.setContentType(contentType);response.setHeader("Content-Length", String.valueOf(image.length()));response.setHeader("Content-Disposition","inline; filename=\"" + image.getName() + "\"");BufferedInputStream input = null;BufferedOutputStream output = null;try {input =new BufferedInputStream(new FileInputStream(image), DEFAULT_BUFFER_SIZE);output =new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];int length;while ((length = input.read(buffer)) > 0) {output.write(buffer, 0, length);}} finally {close(output);close(input);}}private static void close(Closeable resource) {if (resource != null) {try {resource.close();} catch (IOException e) {e.printStackTrace();}}}} and Finally use this example to get get images based on its unique name based on its values saved in db source="/imagestorage/#{bindings.ImageDirectory.inputValue}" Good Luck تم تعديل 31 أكتوبر 201213 سنة بواسطة oracle_itself تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.