Hi,
I wanted to make a custom quicklink to be able to upload file from local onto server.
I am stuck at being able to execute method on form submission but file is nowhere to be found. I’ve put two separate buttons for test purpose, but none reads the file.
The issue WHich I find in your code is there is a mismatch,You’re using t:inputFileUpload and p:fileUpload on the same form, but your bean property is typed as:
The t:inputFileUpload binds to org.apache.myfaces.custom.fileupload.UploadedFile, so when when tries to call setUploadedFile(), the type doesn’t match, and the value never gets ses. You have to pick one content
@blazejbadzio I am not sure but having both Tomahawk and PrimeFaces tags in the single form could cause issues. When i worked on a similar project in 7.x (see the image for namespaces i used), I didn’t use PrimeFaces, i made it work with Tomahawk but in later versions, you need to use PrimeFaces only. Architecture has been changed.
I checked latest version artefacts and not able to find tomahawk reference in xhtml, but primefaces are there. Sample file: appPage.xhtml
Also check if there are sufficient permissions to write in D drive which you are trying.
Note: Found a fix?Help the community by marking the comment as solution. Feel free to react(,, etc.)with an emoji to show your appreciation or message me directly if your problem requires a deeper dive.
Tried both solution from You and from @naveenkumar3 , neither worked. The access to target directory doesn’t matter since i am failing on “having the file” not saving it.
can you show me the code, which you tried after removing “remove the p:fileUpload component from your XHTML entirely” and after updating the import statement.
@blazejbadzio Could you please confirm if the artefacts you shared above is the complete set? If something is missing or additional object are there, please share. Will configure and test it out. thanks.
There’s also a simple workflow but i don’t thing it’s of any issue since it’s a simple one.
Workflow
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Workflow PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Workflow explicitTransitions="true" name="Workflow-Upload-NIC-file" type="UpdateIdentity">
<Variable initializer="true" name="transient"/>
<Variable input="true" name="requester"/>
<Variable input="true" name="lastApprovalState"/>
<Variable input="true" name="approved"/>
<Variable initializer="Upload NIC file" name="flow"/>
<Variable initializer="false" name="optimisticProvisioning"/>
<Variable initializer="spadmin" name="fallbackApprover">
<Description>A String that specifies the name of the Identity that will
be assigned any approvals where the owner of the approver
can&#39;t be resolved. Example if the scheme is &quot;owner&quot; and the
application doesn&#39;t specify and owner.</Description>
</Variable>
<Step icon="Start" name="Start" posX="28" posY="10">
<Approval mode="serial" name="NIC File Upload Form" renderer="uploadNicFileForm.xhtml" owner="ref:requester">
<Arg name="workItemType" value="Form"/>
<Arg name="workItemForm" value="string:Form-Upload-NIC-file"/>
<Arg name="workItemType" value="Generic"/>
</Approval>
<Transition to="Stop" when="approved"/>
</Step>
<Step icon="Stop" name="Stop" posX="508" posY="10"/>
</Workflow>
Without this filter, t:inputFileUpload will NEVER bind the file — it stays null regardless of type.
Wrong Import After Type Fix
import org.apache.myfaces.custom.fileupload.UploadedFile;
// NOT org.primefaces.model.file.UploadedFile
enctype on h:form
The enctype="multipart/form-data" must be set correctly. With Tomahawk, use:
<!-- Change this -->
<h:form enctype="multipart/form-data">
<!-- To this (Tomahawk specific attribute) -->
<h:form enctype="multipart/form-data" id="uploadForm">
Remove the valueChangeListener from t:inputFileUpload
<!-- Remove valueChangeListener, it's not needed for file upload -->
<t:inputFileUpload
value="#{uploadNICFile.uploadedFile}"
uploadThresholdSize="1000"/>
<!-- Remove: valueChangeListener="#{uploadNICFile.upload}" -->
try this and please share your web.xml if the issue is still ther
Hi @blazejbadzio , I faced a similar issue 4 years ago. Let me tell you what we did for this scenario. When the CSV file is uploaded into the plugin, we converted the CSV file to JSON before calling the API instead of directly sending raw data file. Send the JSON data into the API. Without any issue, it is working. You can try this approach if you are still unable to upload the raw file and read it in the API Java file. I hope this will be handled smoothly.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Workflow PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Workflow created="1775718388251" explicitTransitions="true" id="7f0000019d701d0e819d7110521b2dd9" modified="1775721074783" name="Community-Workflow-Upload-NIC-file" significantModified="1775721074783" type="UpdateIdentity">
<Variable initializer="true" name="transient"/>
<Variable input="true" name="requester"/>
<Variable input="true" name="lastApprovalState"/>
<Variable input="true" name="approved"/>
<Variable initializer="Upload NIC file" name="flow"/>
<Variable initializer="false" name="optimisticProvisioning"/>
<Variable initializer="spadmin" name="fallbackApprover">
<Description>A String that specifies the name of the Identity that will
be assigned any approvals where the owner of the approver
can&#39;t be resolved. Example if the scheme is &quot;owner&quot; and the
application doesn&#39;t specify and owner.</Description>
</Variable>
<Step icon="Start" name="Start" posX="28" posY="10">
<Approval mode="serial" name="NIC File Upload Form" owner="ref:requester" renderer="uploadNicFileForm.xhtml">
<Arg name="workItemType" value="Test"/>
</Approval>
<Transition to="Stop" when="approved"/>
</Step>
<Step icon="Stop" name="Stop" posX="508" posY="10"/>
</Workflow>
UploadNICFile.java
package org.object;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.servlet.http.Part;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import sailpoint.api.SailPointContext;
import sailpoint.api.SailPointFactory;
import sailpoint.object.WorkItem;
@ManagedBean(name="uploadNICFile")
@SessionScoped
public class UploadNICFile {
private String server;
private Part uploadedFile;
private static final Logger log = LogManager.getLogger("tempFile.Logger");
public UploadNICFile() {
System.out.println("UploadNICFile bean instantiated.");
}
public Part getUploadedFile(){
return this.uploadedFile;
}
public void setUploadedFile(Part uploadedFile){
this.uploadedFile = uploadedFile;
}
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
}
public void cancelAction(){
System.out.println("cancelAction() called.");
this.uploadedFile = null;
}
public String saveAction() {
System.out.println("saveAction() ENTERED.");
log.info("saveAction() triggered.");
log.info("Server value = " + this.server);
log.info("UploadedFile (Part) = " + (this.uploadedFile != null ? this.uploadedFile.getSubmittedFileName() : "null"));
try {
if (uploadedFile != null) {
String fileName = uploadedFile.getSubmittedFileName();
// Clean filename from path characters
if (fileName != null) {
if (fileName.contains("\\")) {
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
} else if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
}
} else {
fileName = "uploaded_file_" + System.currentTimeMillis();
}
String baseDir = "<YourDirectory Path>";
File dir = new File(baseDir);
if (!dir.exists()) {
dir.mkdirs();
}
File targetFile = new File(dir, fileName);
System.out.println("Attempting to save to " + targetFile.getAbsolutePath());
log.info("Saving file to: " + targetFile.getAbsolutePath());
try (InputStream input = uploadedFile.getInputStream();
OutputStream output = new FileOutputStream(targetFile)) {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
System.out.println("File saved successfully: " + targetFile.length() + " bytes");
log.info("File saved: " + targetFile.length() + " bytes");
try {
SailPointContext context = SailPointFactory.getCurrentContext();
// Retrieve the Work Item ID from the request parameter
String workItemId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
if (workItemId != null) {
WorkItem wi = context.getObjectById(WorkItem.class, workItemId);
if (wi != null) {
System.out.println("Completing Work Item " + workItemId);
log.info("Automatically completing Work Item: " + workItemId);
wi.setState(WorkItem.State.Finished);
wi.setAttribute("approved", true); // Signal workflow transition
context.saveObject(wi);
context.commitTransaction();
}
}
} catch (Exception ex) {
System.err.println("Work Item Completion failed: " + ex.getMessage());
log.error("Error during automatic Work Item completion: " + ex.getMessage());
}
this.uploadedFile = null;
return "success";
}
} else {
System.out.println("uploadedFile (Part) is NULL in saveAction.");
}
} catch (Throwable t) {
System.err.println(" CRITICAL ERROR in saveAction():");
t.printStackTrace();
log.error("Failed to save file: " + t.getMessage(), t);
}
return null;
}
}