表单提交时jsf无效值

时间:2014-09-12 15:12:07

标签: jsf

我有一个jsf页面,其中包含一个selectmanylistbox,其值是由我的托管中的函数提供的对象数组。这些对象基于以下简单类:

public class Category {
private String categoryId;
private String categoryName;
private String[] templates;

public Category(String categoryId, String categoryName) {
    this.categoryId = categoryId;
    this.categoryName = categoryName;
}

public Category(String categoryId, String categoryName, String[] templates) {
    this.categoryId = categoryId;
    this.categoryName = categoryName;
    this.templates = templates;
}

public String getCategoryId() {
    return categoryId;
}

public void setCategoryId(String categoryId) {
    this.categoryId = categoryId;
}

public String getCategoryName() {
    return categoryName;
}

public void setCategoryName(String categoryName) {
    this.categoryName = categoryName;
}

public String[] getTemplates() {
    return templates;
}

public void setTemplates(String[] templates) {
    this.templates = templates;
}

以下是为selectonelistbox提供数组的托管bean函数:

public Category[] getCategoryValues() {

    categoryValues = new Category[4];

    String[] temp = new String[3];
    temp[0] = "Line 1";
    temp[1] = "Line 2";
    temp[2] = "Line 3";
    categoryValues[0] = new Category("1001", "Category 1", temp);
    temp = new String[3];
    temp[0] = "Line 4";
    temp[1] = "Line 5";
    temp[2] = "Line 6";
    categoryValues[1] = new Category("1002", "Category 2", temp);

    temp = new String[3];
    temp[0] = "Line 7";
    temp[1] = "Line 8";
    temp[2] = "Line 9";

    categoryValues[2] = new Category("1003", "Category 3", temp);

    temp = new String[3];
    temp[0] = "Line 10";
    temp[1] = "Line 11";
    temp[2] = "Line 12";

    categoryValues[3] = new Category("1004", "Category 4", temp);

    return categoryValues;

}

以下是此selectmanylistbox的jsf代码:

    <h:selectOneListbox value="#{category.selectedCategoryId}"
     onchange="submit()">

        <f:selectItems value="#{category.categoryValues}" var="cat"
            itemLabel="#{cat.categoryName}" itemValue="#{cat.categoryId}" />
    </h:selectOneListbox>

此外,每当选择一个类别时,我都使用以下事件重新加载页面:

<f:event listener="#{category.intialize()}" type="preRenderView" />

重新加载页面的目的是使用selectedcategory作为selectmanycheckbox项目的基础,显示来自selectedcategory的数组作为复选框。这是相应的jsf代码:

<h:selectManyCheckbox value="#{category.targetTemplates}">

        <f:selectItems value="#{category.selectedCategoryTemplates}" />
    </h:selectManyCheckbox>

其中CategoryTemplates是一个字符串对象数组。

现在,类别选择和页面重新加载工作正常,selectmanycheckbox项目正确显示,选定类别的字符串作为选项。当我尝试选择一些复选框值并提交它们时,我收到了一个inavlid值错误消息,并且没有提交。当页面加载时,selectmanycheckbox使用的值可用,那么问题可能是什么?

这是initialize()方法实际上什么都不做,我只是用它来重新加载页面:

public void intialize() {

}

以下是复选框的html代码:

<table>
<tr>
<td>
<input name="j_idt4:j_idt8" id="j_idt4:j_idt8:0" value="Line 1" type="checkbox" /><label   
for="j_idt4:j_idt8:0" class=""> Line 1</label></td>
<td>
<input name="j_idt4:j_idt8" id="j_idt4:j_idt8:1" value="Line 2" type="checkbox" /><label   
for="j_idt4:j_idt8:1" class=""> Line 2</label></td>
<td>
<input name="j_idt4:j_idt8" id="j_idt4:j_idt8:2" value="Line 3" type="checkbox" /><label 
for="j_idt4:j_idt8:2" class=""> Line 3</label></td>
</tr>
</table>

控制台上的实际错误消息是:

j_idt4:j_idt8:Überprüfungsfehler:Wertistungültig。),detail =(j_idt4:j_idt8:Überprüfungsfehler:Wertistungültig。)]

它用德语表示验证失败,值无效

1 个答案:

答案 0 :(得分:0)

检查托管bean的范围,该范围为selectonelistbox提供数组(方法getCategoryValues)。它必须在后续请求中(在提交表单期间)返回与初始请求期间相同的列表(在提交表单之前,在选择值期间)。