Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JSF and the fly likes Setter methods not getting called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Setter methods not getting called" Watch "Setter methods not getting called" New topic

Setter methods not getting called

Hemant Gupta Hg

Joined: Jan 23, 2011
Posts: 11

I am using RichFaces 4.0 M6 and JSF 2.0.4 version. I have written a statement like this

<h:inputTextarea id="someId" value="#{managedBean.comments}" />

I have created setter and getter methods for my "private String comments" variable. However, when I click the submit button, the setter is not getting called and as such I get a null value for comments variable.

Can anyone please tell me what all could lead to such error? It seems that the setter is not called because it has failed the validation phase. The only value I enter is "assd as" in the inputTextArea and then click the submit button. I have set the state to Development in web.xml but I don't get any error which I can use to figure out the problem.

Please anyone tell me how to fix this error.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950

If any field on a form is invalid, no setters will be invoked for ANY property set by that form. You can use the <h:messages/> element to display the error.

If the form is valid, the setter must be a method with a signature like this: "public void setPropertyname(String value) {...}"

The actual argument doesn't have to be a String - for example, you can set Integer properties and char properties. But it does have to be a single-argument method and it MUST be public, returning void.

There is one other way to end up with null data besides not having the setter get called. That's when you have the scope of the property's containing bean set to request and the old copy of the bean was discarded and replaced with a new copy because a new request was being processed.

Customer surveys are for companies who didn't pay proper attention to begin with.
Hemant Gupta Hg

Joined: Jan 23, 2011
Posts: 11

I did put the <h:messages /> on the view but it showed me no error message. I also tried putting immediate=true to see if there was any value being update in the modal value phase. But, both of them didn't work.

Please help me on this one. I have tried everything I could but not getting what's the problem
roby george
Ranch Hand

Joined: Sep 08, 2010
Posts: 31

can you paste all the code of jsf page and managed bean,

Hemant Gupta Hg

Joined: Jan 23, 2011
Posts: 11

Sorry for the late response. But, I can't paste the code here. Its quite big. Rest Assured that I have not committed any mistake in the code. Actually, I am using both Richfaces and JSF tags together.

I think its the issue with RichFaces tags that is not allowing the JSF tags to work properly.

I debugged the code and discovered that after changing to the new version of JSF 2.0.4 the code started working to some extent. Now, this time the setter was called 4 times. In the first time, the value was there but after that value was emptied.

Can you provide me some hint as to why the value was available in first place and then was emptied? I know the could be no validation issue as it was simple string value with just characters.

Waiting for your quick response.
Hemant Gupta Hg

Joined: Jan 23, 2011
Posts: 11

I got some progress in debugging the issue. I am using a4j:repeat inside rich:datatable to print the items that I have. There are 5 items to be printed with each one of them having an inputText field. Along with it is a command button that saves the text in the database for that particular row item

I found that since there are 5 items, the setter for all 5 inputText fields were called when I pressed the commandButton for one of the item.

Why is it so? Why the setter for all other inputText is called when it should not?

Please help me
Hemant Gupta Hg

Joined: Jan 23, 2011
Posts: 11
Problem Solved. I was using one h:form for all the items as a result of which the setters was getting called for every item.
I agree. Here's the link:
subject: Setter methods not getting called
Similar Threads
from is getting submitted when 'Refresh' button is clicked
How to get s:hidden value to java class
form is getting submitted when 'Refresh' button on the browser is clicked.
data table + selectOneMenu