0

This is the snippet of my xhtml page.

<p:dataTable var="doc" value="#{orderCreationBackingBean.documentList}" reflow="true" style="width:70%;margin-top:5px;margin-top:5px;">

    <p:column headerText="Document Name">
        <h:outputText value="#{doc.documentName}"/>
        <p:outputLabel value=" *" rendered="#{doc.docType == 'M' ? true : false}" style="color:red;"/>


    </p:column>

    <p:column style="width:20%;">
        <p:fileUpload fileUploadListener="#{orderCreationBackingBean.handleFileUpload}" mode="advanced" skinSimple="true" sizeLimit="100000"
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/" update="tabView:idformexprocess" auto="true" uploadLabel="Upload" 
            onstart="submitCollection([{name:'docCode', value:'#{doc.documentCode}'},{name:'docName', value:'#{doc.documentName}'}])"/>
        <p:remoteCommand name="submitCollection" process="@this" action="#{orderCreationBackingBean.setValuesForFileUpload}" partialSubmit="true"/>
    </p:column>


    <p:column style="width:20%;">
        <p:commandButton value="View"></p:commandButton>
    </p:column>


</p:dataTable>

In here, most of the times, onstart invokes after the fileuploadlistener.

These are the two methods I'm calling

public void setValuesForFileUpload() {

    FacesContext context = FacesContext.getCurrentInstance();
    Map<String,String> params = context.getExternalContext().getRequestParameterMap();
    String doc = params.get("docCode");
    docCode = new BigDecimal(doc);
    docName = params.get("docName");

}

/**
 * Upload Document in Dynamic Screen
 */
public void handleFileUpload(FileUploadEvent event) {
    File obj = null;
    InputStream inputStream = null;
    if(event != null){
        UploadedFile uploadFile = event.getFile();
        try {
            inputStream = event.getFile().getInputstream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(uploadFile.getFileName());
        documentService.uploadTaskDocuments(username, avaOrderNo, bpmOrderNo, custOrderNo, bpmTaskNameAsID, docCode, event.getFile().getFileName(), uploadFile.getContentType(), uploadFile.getSize(), inputStream, "I", propFileReader.getApiQuery("UPLOADTASKDOCUMENTS"));
    }

    FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
    FacesContext.getCurrentInstance().addMessage(null, message);
}

What should I do to invoke onstart before the listener? Thank you in advance.

  • It appears you just need to access `#{doc}` inside the upload method. What exactly is `#{doc}`? Is it a managed bean or the currently iterated variable of a repeater component? If the former, you should be able to just `@Inject` it. If the latter, you should be able to just EL-evaluate it. – BalusC Apr 18 '16 at 08:57
  • I'm sorry.. I only added the part of my code. doc is the var of datatable.. this whole part is inside a column of datatable. I have updated the question with whole datatable. – Nevindaree Apr 18 '16 at 09:35
  • Yes, as I guessed. Is this helpful then? http://stackoverflow.com/q/27817661 – BalusC Apr 18 '16 at 09:45
  • Wow... I applied the first solution of the given link and it works fine.. I didn't know that we can get the whole object like that and it solves so many problems I had earlier.. Thank you very very much for your assistance.. :) – Nevindaree Apr 18 '16 at 09:58
  • You're welcome. Here's a related link which shows alternate ways: http://stackoverflow.com/q/4994458 – BalusC Apr 18 '16 at 09:59
  • That link is really helpful.. Thank you once again..!! :) – Nevindaree Apr 18 '16 at 10:02

0 Answers0