File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How do I set this managed bean property? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How do I set this managed bean property?" Watch "How do I set this managed bean property?" New topic

How do I set this managed bean property?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436

I have this defined in my faces-config.xml ...


In an instance where I am editing this object, what backing bean Java code do I need to write so that "param.feature_name" is populated with the variable "featureName" in the code below?

public String editBillSet() {
FeatureDef featureDef = npsAppConfig.getSelectedFeatureObj();
String featureName = featureDef.getFeature_name();
// What to do here so that param.feature_name is populated?
return "success";
} // editBillSet

Thanks, - Dave
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17280

I hope I'm understanding this correctly, but maybe I can at least help even if I don't get it quite write.

First, a note: it's not considered good style to name a property using underscores in Java. It's probably not going to bring everything crashing down, but the convention is camelCase, without underscores or other non-alphanumeric characters. Also, I don't recommend naming beans with an initial capital letter, since that confuses object names with Class names. Again, your program will probably work (most of the time, anyway), but it's going to confuse people who read it.

A Managed Bean isn't magic. It's simply an ordinary JavaBean that's been placed under JSF management by defining it in the faces-config xml file.

That means that all the standard set/get rules apply.You've declated that your FeatureDef bean named FeatureDef has a property named "feature_name", so it needs to have a "public void setFeature_name(??? value)" method defined as a setter. Replace "???" with the typename you want to use for the property value.

The one thing I can't make sense of here is that you're declaring a managed bean and setting a property, but your question referes to a completely different propery in a completely different context. "#{param.feature_name}" refers to another managed bean named "param" which has a "public ??? getFeature_name()" method defined.

How does the feature_name property in the "param" managed bean get defined? Either in its constructor, or by initializing it using a property definition to inject it in from faces-config.xml, just like you did for the bean named "FeatureDef".

An IDE is no substitute for an Intelligent Developer.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Thanks for replying. Sometimes it is difficult to get a response on this board!

On a particular JSF page, list.jsf, I have a list of FeatureDef objects with "Edit" links next to them. The idea is if you click an "Edit" link, you go to a new page, item.jsf, where you can edit the fields (one of which being "feature_name") of the FeatureDef object.

Maybe managed beans don't come into play at all here, but when you click the aforementioned "Edit" link, which takes you to a Java "edit" method, what code do you put in that edit method so that you're object's fields are available for editing on the item.jsf page?

Does it make more sense what I'm trying to do?

Thanks, - Dave
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17280

If you're editing items by selecting them from a datatable, the "edit" action processor only needs to do 1 thing, and that's set a backing bean property to reference the current item selection from the data model. Pass back a "success", and set up the faces-config to navigate to the form that does detail editing. The editing form references the fields to be edited as backing bean properties if you use your placeholder to indicate which row you're editing.

You can also use this architecture to create a new row - such set the placeholder to point to a newly-constructed row bean instead of referring to and existing row bean.

A good example of all this and more can be found in Rick Hightower's "JSF For Nonbelievers" articles at IBM DeveloperWorks.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Ok, so let's say once I enter that Java edit action I'm able to get the object/bean. How do I put it in the request such that on the next page (the page to which I'm redircted after "success" is returned) its fields will be available for editing? Do I use "request.setAttribute"?

- Dave
I agree. Here's the link:
subject: How do I set this managed bean property?
It's not a secret anymore!