Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic