Bean properties not being updated

1.2k views Asked by At

My bean is viewscoped. I have a simple string property with a getter and setter. The getter works fine(checked by initialising the property), but not the setter. In the setter method I am building a Stringbuffer using each of the incoming parameter.

Code:

public String getParamval() {
    return paramval;
}

public void setParamval(String paramval) {
    logger.info("Incoming value:" + paramval);
    pvals.append(paramval);
    this.paramval = "VAL";
}

Is that wrong? I have tested within the setter to see if the input string is being passed but apparently the method is not being called/invoked at all. In the view am using a #{} notation.

View:

<c:forEach items="${gdsiGeodataBean.requiredfields}" var="reqs">
        <h:outputLabel  value="#{reqs}:* " />  
        <pou:inputText value="#{gdsiGeodataBean.paramval}" required="true" requiredMessage="Input is required."/> 
</c:forEach>

And why would I wanna build a stringbuffer in a setter method? because, the inputtext are created dynamically based on a dynamic list. I only have one bean property to bind to.

I know I could use a map, but for the same reason as above, i seem not able to updated a map values in the setter method. This is connected to the question I asked here Updating a map value in a managed bean

1

There are 1 answers

3
BalusC On

Even though the approach is entirely wrong (the getter won't return the right value after you submit the form!) and I have already answered your previous question as to using the map, the setter should really be called in this particular case.

That the setter is not called can have several causes. The most famous is that the form isn't been placed inside a <h:form> or that you're incorrectly nesting multiple <h:form>s inside each other. Another cause is that the input component or one of its parents have a rendered attribute which happen to evaluate false during the submit request.