3

私はプリムフェイスで jsf2.0 を使用し、写真をアップロードするために p:fileupload を使用しています。ここでは、バッキング Bean にパラメーターを渡す必要があります。p:fileupload を介してパラメーターを渡すオプションがないという点で、バインディング オプションも使用されましたが、バッキング Bean で null 値を返します...

ここに私のファイルupload.xhtmlがあります

   <h:form  enctype="multipart/form-data">
            <p:panel  header="Upload Photos" id="getImageId" 
             style="font-size:12px;height:499px">
            <p:messages id="messages" for="imaload"></p:messages>
                 <p:fileUpload id="imaload" fileUploadListener="#  
       {ngoPhotoUpload.photoUpload}"  
                           mode="advanced"  multiple="true"   
     immediate="true"
                          update="messages" 
                           allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>

                 <!--  <p:growl life="1000" id="messages"/>   -->

            </p:panel>
        </h:form>

ここに私のバッキングビーンメソッドがあります

public void photoUpload(FileUploadEvent event) throws IOException,
        InterruptedException {

    BufferedImage bufferedImage;
    String tmpFile = scontext.getRealPath(("/ngoPhotos/")
            + event.getFile().getFileName());
    File result = new File(tmpFile);

    byte[] imageByte = event.getFile().getContents();

    storeImage(imageByte, tmpFile);

    String imageName = event.getFile().getFileName();
    String createdby = loginBean.getEmail();

    if (loginBean.getType().equals("admin")
            || loginBean.getType().equals("ngo_coordinator")) {
        if (ngoRegnPojo.getNgo_id() != 0) {
            ngoPhotoBean.setNgo_id(ngoRegnPojo.getNgo_id());
        } else {
            ngoPhotoBean.setNgo_id(loginBean.getUser_id());
        }
    } else {
        ngoPhotoBean.setNgo_id(loginBean.getUser_id());
    }

    ngoPhotoBean.setImageName(imageName);
    ngoPhotoBean.status = "status";
    ngoPhotoBean.setCreatedDate(new Date());
    ngoPhotoBean.setCreatedby(createdby);
    //ngoPhotoBean.setPathName(tmpFile);
    ngoPhotoBean.disable = "false";
    bufferedImage = ImageIO.read(result);
    if (bufferedImage.getWidth() <= 400 && bufferedImage.getHeight() <= 400) {

        ngoPhotoBean.disable = "false";
        getMthd(imageByte, tmpFile);

    } else {

        try {

            ngoPhotoBean.disable = "false";
            bufferedImage = ImageIO.read(result);
            ImageIO.write(resize(bufferedImage, 400, 400), "jpg", new File(
                    tmpFile));
            photoUploadDaoService.uploadNgoPhoto(ngoPhotoBean);
            NgoPhotoBean ngoPhotoBean = new NgoPhotoBean();
            FacesContext.getCurrentInstance().getExternalContext()
                    .getSessionMap().put("ngoPhotoBean", ngoPhotoBean);
            FacesMessage msg = new FacesMessage("Successfully Uploaded");

            FacesContext.getCurrentInstance().addMessage(null, msg);

        } catch (Exception e) {
            e.printStackTrace();
            FacesMessage error = new FacesMessage(
                    FacesMessage.SEVERITY_ERROR,
                    "The files were not uploaded!", "");
            FacesContext.getCurrentInstance().addMessage(null, error);
        }
    }
}

前もって感謝します

4

2 に答える 2

1

p: remotecommand を使用できます。たとえば、ファイルアップロードの oncomplete で p:remote コマンドを呼び出し、パラメーターを渡す関数を呼び出すことができます。私は自分のプロジェクトで似たようなことをしましたが、かなりうまくいきました。

于 2012-06-07T07:25:20.470 に答える
1

渡す必要があるパラメーターの種類は?それが単なる定数の場合は、送信後にその値を受け取ることができるように、非表示フィールドをフォームに配置します。

于 2012-06-06T07:02:48.657 に答える