0

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

Community
  • 1
  • 1
algone
  • 93
  • 1
  • 2
  • 9

1 Answers1

3

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The wizard component is in a within a that is inside a dialog component. There are no other forms inside this form nor in the dialog component. In the view, there is nowhere where the rendered attribute is set to false. I guess I need to check the viewtree to ascertain this. – algone Jan 06 '12 at 13:02
  • Something strange is happening. I replaced tag with tag and now the setter works. Why is this so? – algone Jan 06 '12 at 13:10
  • Apparently you're relying on a view render time expression. Long story short: http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense – BalusC Jan 06 '12 at 13:14