• 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 do I set this managed bean property?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

<managed-bean>
<managed-bean-name>FeatureDef</managed-bean-name>
<managed-bean-class>com.myco.nps.config.common.beans.FeatureDef</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>feature_name</property-name>
<value>#{param.feature_name}</value>
</managed-property>
</managed-bean>
...
<navigation-rule>
<display-name>jsp/ConfigFeatures</display-name>
<from-view-id>/jsp/ConfigFeatures.jsp</from-view-id>
<navigation-case>
<from-action>#{ConfigFeaturesPage.editFeature}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/jsp/BLS.jsp</to-view-id>
<redirect/>
</navigation-case>

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() {
loadBeans();
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic