0

我的 bean 是 viewscoped。我有一个带有 getter 和 setter 的简单字符串属性。getter 工作正常(通过初始化属性检查),但不是 setter。在 setter 方法中,我正在使用每个传入参数构建一个 Stringbuffer。

代码:

public String getParamval() {
    return paramval;
}

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

那是错的吗?我已经在 setter 中测试了是否正在传递输入字符串,但显然该方法根本没有被调用/调用。在视图中使用 #{} 表示法。

看法:

<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 方法中构建一个字符串缓冲区?因为,输入文本是基于动态列表动态创建的。我只有一个 bean 属性可以绑定。

我知道我可以使用地图,但出于与上述相同的原因,我似乎无法在 setter 方法中更新地图值。这与我在此处提出的问题Updating a map value in a managed bean

4

1 回答 1

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.

于 2012-01-06T11:58:01.040 回答