File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access init/property parameters inside bean classes

 
Shashank Rudra
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

Here I have a bean class which updates the database. This may be seen as a DAO class. In this bean's method we are calling a COBOL program based on some criteria. This bean's method is being called though many other calls. These calls are to methods declared in other beans. These calls are originally being initiated out of a servlet (the general course in web application scenario).

Now we want a configurable option, may be a check box at the start of the application loading. This will affect which COBOL program will be called in THEBEAN method.

One way is to edit all the method call starting with the first one in the chain of method calls. But I think that will be a lazy way to do that. Also will lead to bad code. So any one has an idea how to set this up in some properties file and read it from there. In the bean class we don't have access to context or config to get at the file stored on the server. Please help me see it through. TIA.

I am using Tomcat 5.0 Sevlet 2.4 JDK1.5 on windows XP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store a properties file in the classpath. It can be accessed from anywhere.
 
Shashank Rudra
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for quick response. Here is what I am trying to do
(but am not able to get the results as desired please tell what I need to do different)

Code I am using in a servlet, where I have access to session/servletContext. The file is inside the WEB-INF directory as in the path above. Now to
access the same properties file inside a bean class where I don't have
access to session and context objects. As said in the first post- I don't
want to keep them passing through chain of method calls which are 6-8 in number.

I am trying
And this is the error that I am getting Other paths that I have tried with are -
/properties/myProject.properties
./properties/myProject.properties
properties/EZRithm.properties

I am using Tomcat5.0 Servlet2.4 JDK1.5 Eclipse Europa on Windows XP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file is already on the classpath -- you should be using the normal Java properties mechanisms to load it -- not going through the servlet context. You're just making it hard on yourself.

Hint: ResourceBundle
 
Shashank Rudra
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Bear. Now I see it, thanks for the hint. I myself once thought to use that but was not sure.

Here is how I accessed itThe fileName that I used is properties.myProject.

Thanks a lot again Bear.
 
ravil baizhiyenov
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was looking for information about how to solve the same problem and came across this topic... Just to help others out with a similar issue, I'd encourage them to see the following article: http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=1. I found it quite helpful...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic