cancel
Showing results for 
Search instead for 
Did you mean: 

Problem related to button action

Former Member
0 Kudos

Hello,

I'm trying to upload a file into server, I got the code from the net. When I try to run my application from my local server, everything is just fine and works.

When I deploy my application on our remote server, I got the following problem :

- If I don't choose a file to upload, the action is executed

- Else nothing happend, as if I didn't enter a file.

Have anyone encountred such a problem?

Thanks in advance for your help.

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

put your code here, please

Former Member
0 Kudos

Thank you for replying John.

Here is my code :


public void onActionUserMapped(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionUserMapped(ServerEvent)
	IWDMessageManager msgmgr = wdComponentAPI.getMessageManager();

	IPrivateUploadFileView.IContextElement element = wdContext.currentContextElement();
	
	msgmgr.reportSuccess("Entrée dans la méthode.");	

	//if a file in the FileUpload field exists
	if (element.getFileResource() != null) 
	  {
	   IWDResource resource = element.getFileResource();
		
	   String fileextension = resource.getResourceName();
	   
	   int cut = fileextension.lastIndexOf(".");
		       
	   String ext = fileextension.substring(cut+1,fileextension.length());
	   
	   if(ext.equals("csv"))
		 {
		  File fp = new File (resource.getResourceName());
		  try
		     {
			  if (fp.exists())
			    {
				 msgmgr.reportException("Il existe déjà un fichier avec le même nom sur le serveur, changez le nom du fichier et réessayer SVP",true); 
			    }
			  else
			 	  {	
				   fp.createNewFile();
				   
				   wdContext.createContextElement().setFilePath(fp.getAbsolutePath());
						     
				   FileOutputStream fos = new FileOutputStream(fp);
				   BufferedOutputStream bos = new BufferedOutputStream(fos);
				   InputStream fileInputStream = resource.read(false);
				   
				   int noOfBytes = fileInputStream.available();
				   byte[] byteArray = new byte[noOfBytes];
						     
				   fileInputStream.read(byteArray, 0, noOfBytes);
				   bos.write(byteArray);
			       bos.flush();
				   bos.close();
							 
				   //On vide la structure au cas où elle a déjà été utilisée
				   wdThis.wdGetMappingPortalUsersController().clearBeforeMappingNode();
				   wdThis.wdGetMappingPortalUsersController().clearAfterMappingNode();
				   wdThis.wdGetMappingPortalUsersController().clearErrLogs();	 
				   
				   //On lit le fichier uploadé
				   wdThis.wdGetMappingPortalUsersController().readCSV(wdContext.createContextElement().getFilePath());
				   
				   //On supprime le fichier car les données sont recopiées dans le noeud du contexte.
				   fp.delete();
				   
				   wdThis.wdGetMappingPortalUsersController().simulateMappingCreation();
				  }
			  }
		 catch(FileNotFoundException fnfe)
				 {
				  msgmgr.reportException("Error while reading file : " + fnfe.getMessage(),true);
				 }				   
		 catch (IOException ioe)
			  {
			   msgmgr.reportException("Error while reading file : " + ioe.getMessage(),true);
			  }

		}
		          
	 else
	     {
		  msgmgr.reportException("Please, choose a CSV file",true);
		 }  
    } 
    
   else 
	   {
		//Si pas de fichier dans FileUpload field 
		msgmgr.reportException("Please, select a file first",true);
	   }
   msgmgr.reportSuccess("Sortie de la méthode");		 
   element.setFileResource(null);
    
   wdThis.wdFirePlugToMappedUsers();
    //@@end
  }

Thanks in advance for you help.

junwu
Active Contributor
0 Kudos

first please debug your application to get detail info.

if you are in NW7, you can save the file to KM.

if you are in CE, you can save the file to ECM.

now in your code, you just write to local drive. maybe you don't have write permission in the remote server.

Former Member
0 Kudos

Thanks a lo for your reply.

For debugging, I can't do this because the debug mode on remote server is off.

For your suggestion, writing into KM, I'll try it and I'll keep you up-to-date.

Thanks again for your reply, I assigned points to you

Answers (3)

Answers (3)

Former Member
0 Kudos

Solved

Former Member
0 Kudos

Hi,

I did not understand the logic, looks like , ur reading the csv file and adding creating a new one.

1. Comment the wdThis.wdFirePlugToMappedUsers() to stop the navigation temporarily until u make sure the code is working.

2. Try to display the read content, and display it so that u can see if its reading the file.

3. Make sure you have the write permissions to create the file.

4. Temporarily put some more messages

a. when file resource is not null

b. before creating the file

5. Also put the catch (Exception ex) block to see if some thing goes into Exception

Regards

Yugandhar Reddy

Former Member
0 Kudos

Hello, thank you for relpying again

I have resolved a part of my problem.

When I was trying to choose a file to upload into the remote server, the fileuplad UI was remaining blank. It's due to a configuration which should be done on Visual Administrator because the multipart-form is never parsed : (I found a post on SDN about it), To do this configuration :

- Start Visual Admin,

- Go to "Cluster" tab => "Server" node => "Services" node => Web Container,

- then tab "Properties",

- then change MultipartBodyParameterName from "empty string" to "com.sap.servlet.multipart.body"

For my code, I change it so I don"t have to create file into server and this just by using Java IO API.

Now, I'm waiting for administrator to do the configuration so I can confirm that my problem is solved.

PS : points are assigned to everyone who try to help.

Thank you all

Edited by: ImaneA on Jul 5, 2011 4:14 PM

Former Member
0 Kudos

I see lot of messages in your code.

What exception or message ur getting from ur code.

Also make sure there is write permissions to create files.

-Yugandhar Reddy

Former Member
0 Kudos

Thank you for replying.

If I don't choose any file to upload, I get the exception message :

"Please, choose a file first"

Else, I don't have any exception message shown, I don't even get this message :

"Entrée dans la méthode."

which should be displayed once I get into the method.

Imane.