Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access widgets from ManagedBean  RSS feed

 
Varun Su
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am new to coderanch and JSF/ Primefaces :-)

The following is a problem for me for 2 days now.

I would like to add two date values and subtract two date values.



A managed bean is called on the click of a submit button and updates two outputext fields SUM and DIFFERENCE.


I believe the above could also be done as :



My question: How does one read the two 'IDs' or 'WIdgetVars' from the managedbean (.java) file to add them and subtract them later and store the values back into 'SUM' and 'DIFFERENCE'?

Thank you in advance!

-V
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is based on the Model/View/Controller architectural scheme and one of the principal aspects of MVC is that the Model (ManagedBean) should not be "accessing" the View (widgets). That's the job for the Controller.

It looks like you missed one of the most basic of Sun's tutorials for JSF, since the "add 2 numbers" app was one of its simplest illustrations.

The way you do the "add 2 numbers" is that you define a View with 2 input controls and an action button (commandButton). When the user clicks the action button, its action method is invoked, and the action method in the backing bean (ManagedBean) will do the addition of the 2 input control properties and set the results in a third property, which the JSF controller will then render back to the View.

You really do need to do a lot of study, not just on JSF, but on the fundamental concept of JavaBeans. To begin the names of bean instances and bean properties (for example, "Bean.Till") is not only against JavaBean rules, it can cause various tools that use these objects to malfunction.

And you don't need the actionListeners at all. People hardly ever need actionListeners.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!