Bean属性未更新 [英] Bean properties not being updated
问题描述
我的bean被视域化了.我有一个简单的带有getter和setter的字符串属性. getter可以正常工作(通过初始化属性进行检查),但是setter不能正常工作.在setter方法中,我正在使用每个传入参数构建一个Stringbuffer.
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.
代码:
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.
查看:
<c:forEach items="${gdsiGeodataBean.requiredfields}" var="reqs">
<h:outputLabel value="#{reqs}:* " />
<pou:inputText value="#{gdsiGeodataBean.paramval}" required="true" requiredMessage="Input is required."/>
</c:forEach>
为什么我要在setter方法中构建字符串缓冲区?因为,inputtext是基于动态列表动态创建的.我只有一个要绑定的bean属性.
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.
我知道我可以使用地图,但是由于与上述相同的原因,我似乎无法在setter方法中更新地图值.这与我在这里提出的问题有关
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
推荐答案
即使方法是完全错误的(提交表单后,getter不会返回正确的值!),我已经回答了您的关于使用地图的先前问题,在这种特殊情况下,应该真正调用设置器.
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.
未调用setter的原因可能有多种.最著名的是该表单未放置在<h:form>
内,或者您在彼此之间错误地嵌套了多个<h:form>
.另一个原因是输入组件或其父项之一具有rendered
属性,该属性恰巧在提交请求期间评估false
.
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.
这篇关于Bean属性未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!