Bean properties not being updated

点点圈 提交于 2019-12-12 02:29:25

问题


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:


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.



来源:https://stackoverflow.com/questions/8756102/bean-properties-not-being-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!