Skip to Content
0
Former Member
Jun 02, 2008 at 09:47 PM

Problem with PAI (Process After Input) in JSPDynpage

29 Views

Hi All,

I am implementing a file upload functionality through JSPDynpage. When I browse the excel file and try to upload it, it gives this error :

com.sapportals.htmlb.page.PageException: Eventhandler- "upload_file" or "onUpload_file" not found!
	at com.sapportals.htmlb.page.DynPage.doProcessCurrentEvent(DynPage.java:168)
	at com.sapportals.htmlb.page.PageProcessor.handleRequest(PageProcessor.java:115)
	at com.sapportals.portal.htmlb.page.PageProcessorComponent.doContent(PageProcessorComponent.java:134)

This is my component :


public class FileUploadUtility extends PageProcessorComponent {

  public DynPage getPage(){
    return new FileUploadUtilityDynPage();
  }

  public static class FileUploadUtilityDynPage extends JSPDynPage{
  
    private fileUpload fileUploadBean = null;
    
    
	protected IPortalComponentRequest request;
	protected IPortalComponentResponse response;
	protected IPortalComponentSession session; 
	protected IPortalComponentContext context;
	protected IPortalComponentProfile profile;
	protected String userId;
	
	/*
	private final static int INITIAL_STATE = 0;    
	private final static int OUTPUT_STATE = 1;
	private final static int ERROR_STATE = 2;  
	private int state = INITIAL_STATE;
    */
  
    public void doInitialization(){
		request = (IPortalComponentRequest) this.getRequest();
		session = ((IPortalComponentRequest)getRequest()).getComponentSession();
		context = request.getComponentContext();
	    
	    
		profile = context.getProfile();
		IUserContext userContext = request.getUser();
		userId = userContext.getUserId();
		System.err.println("berry + Getting userID " + userId);			
		fileUploadBean = new fileUpload();
		session.putValue("fileUploadBean", fileUploadBean);
		//uploadUtility();
    }

    public void uploadUtility(){
    	
		String mimetype;
		String resourceName;
		String repository;
		FileInputStream sourceFileInput = null;
		
		IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();
				
	/*	IWDClientUser wdUser = WDClientUser.getCurrentUser();
		IUser user = wdUser.wdUser.getSAPUser(); */ 

		
		IUser epUser=(IUser)request.getUser().getUser();
		System.err.println("epUser - " + epUser);
		ResourceContext ctx = new ResourceContext(epUser);
		repository = "/Folder1/Folder2";
		RID rid=RID.getRID(repository);
		System.err.println("getting RID :- " + rid);
		IPageContext context = PageContextFactory.createPageContext(request,response);

	//	PageContext context = PageContextFactory.createPageContext(request, response);
		Event event=context.getCurrentEvent();
		
		if(null!=event)
		{
			String event_name=event.getAction();
			if(null!=event_name && event_name.trim().equalsIgnoreCase("upload_file"))
				{
				//FileUpload fileUpload = (FileUpload)context.getComponentForId("fileupload");
				FileUpload fileUpload = (FileUpload)context.getComponentForId("fileupload");
				
					if(null !=fileUpload && null!=fileUpload.getFile())
							{
							mimetype = fileUpload.getFile().getContentType();
							resourceName = fileUpload.getFile().getFileName();
							//sourceFileInput = new FileInputStream(fileUpload.getFile().getFile().getAbsolutePath());
							
							try {
								sourceFileInput = new FileInputStream(fileUpload.getFile().getFile().getAbsolutePath());
							} catch (FileNotFoundException fnf) {
								System.err.print("FileNotFoundException Occured " + fnf.toString()); 
							}
							
							
							Content content = new Content(sourceFileInput, mimetype, -1L);
							//IResource resource = (ResourceFactory.getInstance().getResource(rid, ctx));
							
							IResource resource = null;
							try {
								resource =(IResource) (ResourceFactory.getInstance().getResource(rid, ctx));
							} catch (ResourceException resexp) {
								System.err.print("Resource Exception Occured for IResource" + resexp.toString()); 					}
							
							
							ICollection aCollection=(ICollection)resource;
							//IResource newResource = aCollection.createResource(resourceName, null, content);
							try {
								IResource newResource = (IResource) aCollection.createResource(resourceName, null, content);
							} catch (NotSupportedException e2) {
								System.err.print("Not Supported Exception Occured" + e2.toString());
							} catch (AccessDeniedException e2) {
								System.err.print("Access Denied Exception Occured" + e2.toString());
							} catch (ResourceException e2) {
								System.err.print("Resource Exception Occured for ICollection" + e2.toString()); 	
							}//end of catch
				}//end of innermost if
		}//end of 2nd if
	}//end of 1st If
  	
}// end of uploadUtil


    public void doProcessAfterInput() throws PageException {
		uploadUtility();
    }

    public void doProcessBeforeOutput() throws PageException {
      this.setJspName("File_Upload.jsp");
    }
  }
}


Kindly help with expert suggestions :