开发者

Error in JSF 2 with Ajax call to update parts based on request parameters

I'm quite new to JSF 2. I'm trying to render a component using Ajax depending on which checkbox the users choose. For example, check box 1, box 2, and box 3.

I'm having some errors whenever I choose a checkbox.

Error message:

serverError: class javax.faces.component.UpdateModelException/ajaxcall.xhtml@27,
54 value="#{bean.panels}": Property 'panels' not writable on type java.util.List

Below is 开发者_开发问答my XHTML code.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
>
    <h:head><title>JSF 2.0: Blank Starting-Point Project</title>
    </h:head>

    <h:body>
        <h:panelGroup id="panels">
            <h:panelGroup rendered="#{bean.panels.contains('u1')}">
                panel one
            </h:panelGroup>
            <h:panelGroup rendered="#{bean.panels.contains('u2')}">
                panel two
            </h:panelGroup>
            <h:panelGroup rendered="#{bean.panels.contains('u3')}">
                panel three
            </h:panelGroup>
        </h:panelGroup>

        <h:form>
            <h:selectManyCheckbox value="#{bean.panels}">
                <f:selectItem itemValue="u1" />
                <f:selectItem itemValue="u2" />
                <f:selectItem itemValue="u3" />
                <f:ajax render=":panels" />
            </h:selectManyCheckbox>
        </h:form>
    </h:body>
</html>

This is my bean:

package somePackage;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class Bean {
    private List<String> panels = new ArrayList<String>();

    public List<String> getPanels() {
        return panels;
    }
}

Am I missing something?


The error is a bit misleading, but you need a setter as well.

public void setPanels(List<String> panels) {
    this.panels = panels;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜