• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not connecting to backing bean  RSS feed

 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing my first JSF and am having problems connecting to my backing bean.

My submit looks like this:



the save method in HealthAssessmentFormImpl is simple just to do an initial test:


This is the error I am getting: javax.servlet.ServletException: javax.el.PropertyNotFoundException: /jsf/assessment/healthAssessmentForm.xhtml @41,110 action="#{HealthAssessmentFormImpl.save()}": Target Unreachable, identifier 'HealthAssessmentFormImpl' resolved to null

Any ideas why it is not finding the method? Thanks in advance!
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the HealthAssessmentFormImpl code?

If you need a hello world for JSF you can find it here: JSF – Hello World, Auto Complete
 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code:

 
Louis Bros
Ranch Hand
Posts: 54
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does @Component("HealthAssessmentForm") name your Spring bean 'HealthAssessmentForm'?

In that case you would use that name and not 'HealthAssessmentFormImpl'.

Louis
 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the interface to the Impl class. That is the example I am following. I tried using the interface in the submit and that did not work either.
 
Louis Bros
Ranch Hand
Posts: 54
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not too sure about Spring but since you're using save() as an action method, won't you be needing a return type?
 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I will eventually, but I am just trying to get the connection to work first, then I can work on a full implementation of the save method.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Schrader wrote:yes, I will eventually, but I am just trying to get the connection to work first, then I can work on a full implementation of the save method.

Try something like:
 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I tried that and got the same error with the Impl class as the action of the submit, and when I use the interface class as the submit (HealthAssessmentForm.save()) it I get "action="#{HealthAssessmentForm.save()}": Method save not found
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did you write #{HealthAssessmentForm.save()} if your MB is named HealthAssessmentFormImpl?
 
George Schrader
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the interface to the Impl. I also tried putting the Impl as the action for the submit, but I get the "Target Unreachable, identifier 'HealthAssessmentFormImpl' resolved to null"
 
Phillip Ankerson
Greenhorn
Posts: 27
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<h:commandButton value="Save Assessment" action="#{HealthAssessmentFormImpl.save()}"/>

I didn't think the parenthesis after the bean method were needed...like this:

<h:commandButton value="Save Assessment" action="#{HealthAssessmentFormImpl.save}"/>

But I am technically considered a Greenhorn :-)
 
Louis Bros
Ranch Hand
Posts: 54
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You provided a value with your @Component annotation, so that is the logical name you should use when accessing the bean.

Did you configure auto-detection of components?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is bad practice to capitalize the first character in a JSF bean name. The convention is to capitalize the first character of a classname and lower-case the first character of an instance name. JSF backing beans are instances of the bean classes. When using the @ManagedBean annotation, JSF will by default automatically construct an instance whose name is the same name as the class name, but with its first character in lower case.

You will not be able to "connect" to a backing bean unless all values on the submitted form are valid. Otherwise the JSF validation process will short-circuit the property-update and action phased. Check out the JSF lifecycle for details.

JSF is not a client-server architecture, nor is any web-based (HTTP) system. You don't "call" things in JSF, you submit HTTP requests and get HTTP responses. In the case of commandButton and commandLink controls, that means that an HTTP PUT request is submitted and JSF itself calls the action method. JSF Views are not logic constructs like JSPs are, they are declarations, and by definition, a declaration is not an executable object.

You can force a certain amount of execution into a view, via EL, but beyond simple rendering instructions, that's violating the MVC component separation of concerns (and for the record, a backing bean is NOT a Controller, it's a Model).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!