cancel
Showing results for 
Search instead for 
Did you mean: 

Saving data in a text format through webdynpro.

Former Member
0 Kudos

Hi All,

I have created a form in Webdynpro in which the user enters his details,and i have to capture them .Now when the user clicks the save button the text entered in the form should get stored in a text format(.txt).My backend is oracle.

Thanks and Regards

Nishita

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

for this

1. get the form data from uI elements

2. through FileWriter and BufferedReader classes of java create a text file and write the contents to it.

For eg.

suppose you have 2 input fields, attributes bound to these be, var1 and var2

then you are going to write the file "MyData.txt" in a specified folder

then call this metjodin the action when user clicks the save button


  public void Write_Data_ToTextFile( )
  {
    //@@begin Write_Data_ToTextFile()
	try
	{
                String v1=wdContext.currentContextElement().getVar1();
                String v2=wdContext.currentContextElement().getVar2();
	FileWriter fil = new FileWriter(new File("D:/MyData.txt"));// Path where file to be written. This path will be where the J2EE server is installed
	BufferedWriter bu= new BufferedWriter(fil);
                bu.write("var1="+v1);
                bu.newLine();
                bu.write("var2="+v2);
                bu.close();
               }
               catch(Exception e)
	{}

regards

Smitha

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi

My NWDS version is

Version: 2.0.14

Thanks and Regards

Nishita

Former Member
0 Kudos

Hi Nishita,

we will have this Resource Type in NWDS 2004s version..

If you are using 2004 version, you have to use LinkToURL and bind the value

str only to reference property.. But it'll open the file before prompting to save.

Because there is no WDFileDownLoadBehaviour in 2004. you can save afetr opening file.

Regards

LakshmiNarayana

Former Member
0 Kudos

Hi LakshmiNarayana,

I tried to create the two context attributes as u suggested but,I am not able to find that resource type in my local dictionary.Can u please help me out in this regards can i take any other data type ...

Thanks and regards

Nishita

Former Member
0 Kudos

Hi

What is the NWDI Version you are using . If its NW2004s you will have this.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

try the following

create two context attributes

str of type String

reso of type com.sap.ide.webdynpro.uielementdefinitions.Resource

then Create a child, FileDownload Element as child of RootTransparentContainer

bind properties data-->str

resource-->reso

Then in WdDoInit() write following

FileInputStream fis = new FileInputStream(f);

FileChannel fc = fis.getChannel();

byte[] data = new byte[(int)(fc.size())];

ByteBuffer bb = ByteBuffer.wrap(data);

fc.read(bb);

IWDCachedWebResource objCachedWebResource = null;

if (data != null)

{

objCachedWebResource = WDWebResource.getWebResource(data,WDWebResourceType.XLS);

objCachedWebResource.setResourceName(f.getName());

}

wdContext.currentContextElement().setResource(objCachedWebResource.getAbsoluteURL());

wdContext.currentContextElement().setReso(objCachedWebResource);

wdContext.currentContextElement().setBehaviour(WDFileDownloadBehaviour.ALLOW_SAVE);

This will allow you to save ur file in local desktop

Regards

LakshmiNarayana

Former Member
0 Kudos

Hello,

Thank you so much.Your solutions worked out and I could save it in the text file .But the text file is getting saved at the server.Is there any means where i can store the data on the local desktop ie in the system where i open the portal not the server.

Former Member
0 Kudos

Hi,

This blog shows you the step by step procedure for handling file in local desktop.

/people/shabarish.vijayakumar/blog/2006/08/01/along-came-a-file-adapter-mr-ftp-and-rest-of-the-gang

Hope this will help u

Regards,

Smitha

Former Member
0 Kudos

Hi,

or you have to use LinkToURL

-- Create the text file (eg. Mydata.txt) to some location in the server (eg: D:\sm)

-- Create a HTTP alias(eg. da1)in the Visual Adminsitrator pointing to the file location (eg: D:\sm).

--Set the linkToURL reference property to http://<<local machineName>>:50000/sm/<<text file name>>

For creating the HTTP alias refer to the blog "Creating an HTTP Alias in WAS"

<a href="/people/renjith.andrews/blog/2005/03/31/creating-an-http-alias-in-was an HTTP Alias in WAS</a>

thanks

smitha

Former Member
0 Kudos

Hi,

1.Create a text file.

2. Iterate through the elements of the node bind to the table.

3. Write the element to the file

4. Close the file

Sample Code

StringBuffer strBuf = new Stringbuffer();

for(int x=0; x< wdContext.nodeTest().size(); x++) // Replace nodeTest with yours

{

ITestElement nodeElement = wdContext.nodeTest().getElementAt(x);

strBuf.append(nodeElement.getAttribute("TestAttribute"); //Replace with yours

strBuf.append(nodeElement.getAttribute("TestAttribute"); //Replace with yours

strBuf.append("\n");

}

try

{

FileWriter fileWriter = new FileWriter("data.txt");

fileWriter.write(strBuf.toString());

fileWriter.close();

}catch(Exception e)

{

e.printStackTrace();

}

Regards

Ayyapparaj