Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • 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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!