aspose file tools*
The moose likes JSF and the fly likes Reading values of the faces-config.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Reading values of the faces-config.xml" Watch "Reading values of the faces-config.xml" New topic
Author

Reading values of the faces-config.xml

Pete Rutters
Greenhorn

Joined: Oct 16, 2012
Posts: 6
Hi,

I want to programaticily read some default values from a managed bean property in a faces-config.xml. Is there a way to do so?

Thanks in advanced

El Gringo
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

First you need to fix your display name. We don't have many rules here at the JavaRanch, but we do insist that you use your Real Name and not some sort of "handle" or obvious alias. If you're not sure about this, see
http://www.javaranch.com/name.jsp .


Customer surveys are for companies who didn't pay proper attention to begin with.
Pete Rutters
Greenhorn

Joined: Oct 16, 2012
Posts: 6
Tim Holloway wrote:First you need to fix your display name. We don't have many rules here at the JavaRanch, but we do insist that you use your Real Name and not some sort of "handle" or obvious alias. If you're not sure about this, see
http://www.javaranch.com/name.jsp .


How did you know this wasn't my real name? Ok, ok.... request is out. ;)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Thanks, Pete! Welcome to the Ranch!

You wouldn't actually "read" faces-config. For one thing, there may be multiple faces-config files and/or annotations at work.

However, since Managed Properties are automatically injected into JSF Managed beans, you don't have to read anything - they're written into the bean at construction time.
Pete Rutters
Greenhorn

Joined: Oct 16, 2012
Posts: 6
Tim Holloway wrote:Thanks, Pete! Welcome to the Ranch!

... However, since Managed Properties are automatically injected into JSF Managed beans, you don't have to read anything - they're written into the bean at construction time.


Thank you for the warm welcome

The bean was allready injected. In runtime some of the properties in the bean where changed. So what I want to do now, is to restore some of the inital values. Therefore I need a way to get those properties from the faces-config.xml.

At least that was the best shot I came on with.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Actually, you would be better off simply caching the value within your bean. That can be done quite simply in POJO code:
Pete Rutters
Greenhorn

Joined: Oct 16, 2012
Posts: 6
Tim Holloway wrote:Actually, you would be better off simply caching the value within your bean. That can be done quite simply in POJO code:


Much obliged!
I think this should work. The downside is that you have to double all the relevant properties and it feels a little bit clumpsy. On the other side in I my case there aren't that much properties, so it still is practicable.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Can't argue that. The upside is that you don't need any JSF-specific code, which means

A) it won't break when the JSF internals get redesigned - and I fully expect at least one more major internal overhaul before JSF is truly tidy inside.

B) Because the JSF and web frameworks are not involved, you can test the bean using stand-alone unit tests

C) Since the bean isn't platform-specific, you have the option to use it in any other place it might be a good fit - even non-web uses.

Oh, and

D) Since it's POJO, virtually anyone can figure out what it's doing and how to maintain it. No arcane inside knowledge required. So you can dump it on the first junior programmer and run off to new and more exciting adventures!
Pete Rutters
Greenhorn

Joined: Oct 16, 2012
Posts: 6
Full Ack! Though you allready got me on the your previous post.

What do you think of aproaching your idea from an other side?
I provide a interface (let's called it defaultable) that let you implement a function to store a deep copy of the bean into a backup property.
After the bean is injected the backuproutine is called. VoilĂ ! It still covers A, B, C and D.
Just not shure if the overhead would be to big.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Probably overkill in most cases. Have you considered just discarding the backing bean altogether and letting JSF build a whole new bean when it needs a fresh one?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading values of the faces-config.xml