• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Access Another Class' Property Value that is Defined in the faces-config.xml?

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a private property "dataTransferType" with public getter and setter in the DataFile class. The initial value of the "dataTransferType" is defined in the faces-config.xml file. I want to get the "initial value" of the "dataTransferType" in another class and the compiler does not like the way I access this property.

Here is the snippet of the DataFile class, which shows the declaration and the getter and setter for the property:

Here is the way that the initial value of the "dataTransferPropery" is set in the faces-config.xml file:

Now, in another class FileManagementBean, I first instantiate the DataFile class

and then in the constructor of the FileManagementBean I tried to access the initial value of the property "dataTransferType":

The compiler did not like it at all.

But, if I arbitrary introduced a String in the FileManagementBean:

My code worked as I had expected without any problem.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this.recordItems = this.getRecordsList( datafile.dataTransferType );
The compiler did not like it at all.



Without knowing what the compiler said, I'd guess it's because there is no dataTransferType method. This is basic java. Try datafile.getDataTransferType().

Also, creating a new DataFile object in another backing bean won't work. What you will have to do is in FileManagementBean created at least a setter for a private DataFile. Then, you can do a managed-propety in your backing bean for FileManagementBean.



I *think* this will work but keeping mind the dataFile bean must exist before it is really available.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the public getter and setter for the private object DataFile in the FileManagementBean.

Before I posted my question, I had tried both


and I followed your advice to add:

The runtime error has alway been:


javax.servlet.ServletException: javax.faces.FacesException: javax.faces.FacesException: Can't instantiate class: 'actions.FileManagementBean'.. class actions.FileManagementBean : java.lang.NullPointerException

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic