cancel
Showing results for 
Search instead for 
Did you mean: 

Properties file

Former Member
0 Kudos

hi all,

how to work with properties file?. how to write it?. wr to save the properties file in web dynpro java?. and how to access it.

regards,

shreeharsha

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

Hi

1. Create one notepad file and save it as .properties file.

2. write the key and values there as follow:-

a=1.2345

b=2.3456

etc.

3. Then save it and put the file in your project at the following location

---src

-


configuration

-


a.properties

4. now in the code where you want to use it write the following


String[] Values = null;
		try {

			IWDConfiguration config =
				WDConfiguration.getConfigurationByName(
					wdComponentAPI
						.getDeployableObjectPart()
						.getDeployableObject(),
					"<name of the file>");
			Values = config.getStringEntries(<Key>);

		} catch (Exception e) {
			
		}

Now values contain the value of the porperty having specified key

Thanks,

Sarbjeet singh

Former Member
0 Kudos

hi sarbjeet,

my problem is i have a project that came with the netweaver installation. its nothing but simple quiz like project. in the project its displaying the question and answer after the button press. actually its displaying the questions from the properties file Questions and its stored under the 'src' folder. can u please tell me how to do this.....

regards,

shreeharsha

gill367
Active Contributor
0 Kudos

Hello

well you can fetch the questions from the properties file by using the code that i have pasted above.

Suppose you have a text view where you want to display your question then bind that text view to one context attribute of type string.

Suppose name of the context attribute is que1 then in the action or event handler where you want to display the question

write the code

String[] Values = null;
		try {
 
			IWDConfiguration config =
				WDConfiguration.getConfigurationByName(
					wdComponentAPI
						.getDeployableObjectPart()
						.getDeployableObject(),
					"<name of the file>");
			Values = config.getStringEntries(<Key for Question 1>);
wdcontext.currentcontextelement.setQue1(Values[0]); //this will set the question 1 in the context attribute. 

		} catch (Exception e) {
			
		}

Please let me know if you still have some problem in fetching the values.

regards,

Sarbjeet

Former Member
0 Kudos

Hi,

IWDConfiguration config =WDConfiguration.getConfigurationByName - i am getting error in this line

"IWDConfiguration can not resolved" and "WDConfiguration can not be resolved"

wdContext.currentContextElement.setProperty(Values[0]); - here in this line

"wdContext.currentContextElement can not resolved"

this is my Property.properties file look like

Q0 = What is a views?

Q1 = What is a view set?

Q2 = What is a view area?

Q3 = What is a window?

Q4 = What is a view composition?

Q5 = How do you embed views into other views?

Q6 = What is a component interface view?

SIZE = 7

Former Member
0 Kudos

Hi,

Values = config.getStringEntries(Q0);

error "Q0 can not resolved"

this is my Property.properties file look like

Q0 = What is a views?

Q1 = What is a view set?

Q2 = What is a view area?

Q3 = What is a window?

Q4 = What is a view composition?

Q5 = How do you embed views into other views?

Q6 = What is a component interface view?

SIZE = 7

i have saved the properties file under the src->package folder and src->configuration->applicatons folder

gill367
Active Contributor
0 Kudos

Hi

Give it in quotes.

Values = config.getStringEntries("Q0");

Thanks

Sarbjeet

former_member185086
Active Contributor
0 Kudos

Hi

Have a look in this solution.

[Constructing a Recursive and Loadable Web Dynpro Tree|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/47ce9b90-0201-0010-59b5-f70826824eee].

Best Regards

Satish Kumar

gill367
Active Contributor
0 Kudos

Hi

Save Your properties file under src--> Configuration

and right click in code and press organise import.

Regards,

sarbjeet

Former Member
0 Kudos

hi,

errors have been resolved. but it is displaying nothing on the textview after the button click.

regards,

shreeharsha

gill367
Active Contributor
0 Kudos

Could you please write the code you are using for getting the values from the properties file.

Former Member
0 Kudos

String[] Values = null;

try {

IWDConfiguration config = WDConfiguration.getConfigurationByName(wdComponentAPI.getDeployableObjectPart().getDeployableObject(),"Property.properties");

Values = config.getStringEntries("Q0");

wdContext.currentContextElement().setProperty(Values[0]); //this will set the question 1 in the context attribute.

} catch (Exception e) {

}

gill367
Active Contributor
0 Kudos

Hi

Where is your properties file stored?

Could you tell me the path for it?

And is its name Property?

And do one more thing

In the catch part print the exception write the following

 catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);


}
 

Sarbjeet Singh

gill367
Active Contributor
0 Kudos

Hi

Where is your properties file stored?

Could you tell me the path for it?

And is its name Property?

And do one more thing

In the catch part print the exception write the following

 catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);


}
 

Sarbjeet Singh

Former Member
0 Kudos

property file stored under the folder src->configuration

and its name is Property.properties

after the adding code in exception block its giving this message

"Configuration not found: webdynpro/local/ExpProperty/Property.properties"

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

its coming on the textview now. but it displaying only the first question only. after button press its not going to next question.

gill367
Active Contributor
0 Kudos

You want to display all questions in one go or one by one

gill367
Active Contributor
0 Kudos

You want to display all questions in one go or one by one

gill367
Active Contributor
0 Kudos

Hi

1. Add one attribute in the context of type integer say Number

and add the following code in Wddodinint

 wdContext.currentContextElement().setNumber(1);

2. Then add write the code in the action like this

   String[] Values = null;
    int num = wdContext.currentContextElement().getNumber();
    String str = "Q"+num;
	
	try {
			IWDConfiguration config =
							WDConfiguration.getConfigurationByName(
								wdComponentAPI
									.getDeployableObjectPart()
									.getDeployableObject(),
								"a");
					 Values = config.getStringEntries(str);
		} catch (Exception e) {
			
		}
		if(num < 7)
		{wdContext.currentContextElement().setNumber(num +1);
		
		wdContext.currentContextElement().setQuestion(Values[0]);
          }
  else
  {
  	wdContext.currentContextElement().setQuestion("The END");
  }      

Thanks

Sarb

Former Member
0 Kudos

Hi Sarbjeet,

Its working Sarbjeet. Thanks a lot ...

Ragards,

Shreeharsha

gill367
Active Contributor
0 Kudos

People usally give full points on getting the solution.

Former Member
0 Kudos

Hi,

As i said earliar i am new to this. Please tell me how to give points?

Regards,

shreeharsha

gill367
Active Contributor
0 Kudos

Instead of Helpful answer (2) select Solved problem (10)

Former Member
0 Kudos

hi,

k i got it... thank you.....

regards,

shreeharsha

asif_hirani
Active Participant
0 Kudos

Hi Sarbjeet,

Is it possible that in future if we need to change the values (here question's in properties file), to change them without redeploying the code ?

is there any way config / visual admin tool where we can edit this propety file and avoid code redeployment and testing in dev-test-prod environments ?

Thanks !!!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

The quiz application is a standard help tutorial available for Web Dynpro for Java.

It is readily available with coding and documentation on the help.sap.com.

You can find it here: [Quiz Application|http://help.sap.com/saphelp_nw70/helpdata/en/5d/f42fef2eec724597a03b6bcc670c2c/content.htm]

Regards,

Alka.

Former Member
0 Kudos

Hello shreeharshaudupa,

For internationalization, you need to work on .xlf files, these files you can find under Navigator prespective -->respective project --> repective pacakge, where you mentioned while creating the IVIew.

You shouldn't work on .properties file, because even though you make some changes in that .properties file, those changes will disapper when the DC is build. so you have to work with .xlf files of the iviews

For refernece go through below threads

/people/prashant.patalay/blog/2006/12/20/internationalization--i18n-of-webdynpro-java-application

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70361a88-d6ce-2a10-b1bc-c357097a...

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c6cfad90-0201-0010-a5b8-8f948634...

Regards

Maha