javax.el.PropertyNotWritableException:可编辑p:datatable中的java.lang.UnsupportedOperationException

时间:2019-07-11 10:34:05

标签: jsf primefaces datatable

根据此primefaces展示,我正在使用jsf 2.2.18和primefaces 6.2,并尝试实现一个简单的可编辑p:datatablehttps://www.primefaces.org/showcase/ui/data/datatable/edit.xhtml

问题是我无法检查对行的修改。

在Internet上除了发现一些getter / setter问题(没有引起完全相同的错误)之外,什么都没有找到,我只是尝试更改访问器(如果它们是保留字),将#{param.name}替换为#{param.pname}和{ {1}}的{​​1}},没有结果。

这是我表的代码:

#{param.value}

我的控制器:

#{param.pvalue}

我的“环境”豆:

    <h:form id="params_form" prependId="false">
        <p:panel id="context_parameters" header="Paramètres de contexte">
            <p:dataTable id="params" var="param" value="#{displayEnvController.environment.contextParams}" editable="true" style="margin-bottom:20px">
                <p:ajax event="rowEdit" listener="#{displayEnvController.onRowEdit}" update=":params_form" />
                <p:ajax event="rowEditCancel" listener="#{displayEnvController.onRowCancel}" update=":params_form" />

                <p:column headerText="Nom">
                    <p:cellEditor>
                        <f:facet name="output"><h:outputText value="#{param.name}" /></f:facet>
                        <f:facet name="input"><p:inputText id="paramName" value="#{param.name}" style="width:100%" /></f:facet>
                    </p:cellEditor>
                </p:column>
                <p:column headerText="Valeur">
                    <p:cellEditor>
                        <f:facet name="output"><h:outputText value="#{param.value}" /></f:facet>
                        <f:facet name="input"><p:inputText id="paramValue" value="#{param.value}" style="width:100%" /></f:facet>
                    </p:cellEditor>
                </p:column>
                <p:column style="width:32px">
                    <p:rowEditor />
                </p:column>
            </p:dataTable>
        </p:panel>
    </h:form>

还有我的'param'bean:

@Controller
@Scope("view")
public class DisplayEnvController implements Serializable {

    private static final long       serialVersionUID    = 1L;

    private Environment             environment;
    private String                  name;
    @Autowired private DataManager  dataManager;


    /**
     * Called by the view when a parameter is modified.
     * @param event the {@link RowEditEvent} holding the parameter to update
     */
    public void onRowEdit(final RowEditEvent event) {
        dataManager.update((ContextParam) event.getObject());
    }

    public void onRowCancel(final RowEditEvent event) {
        environment.getContextParams().remove(event.getObject());
    }

    /**
     * @return the environment
     */
    public Environment getEnvironment() {
        return environment;
    }

    /**
     * @param environment the environment to set
     */
    public void setEnvironment(final Environment environment) {
        this.environment = environment;
    }

我可以编辑一行,但是当我检查版本时,出现以下错误:

public class Environment implements Serializable {

    private static final long           serialVersionUID    = 1L;

    private final List<ContextParam>    contextParams       = new ArrayList<>();

    /**
     * @return the contextParams
     */
    public List<ContextParam> getContextParams() {
        return contextParams;
    }

    /**
     * @param params the {@link List} of {@link ContextParam}s to set
     */
    public void setContextParams(final List<ContextParam> params) {
        contextParams.addAll(params);
    }

}

(与public class ContextParam implements Serializable { private static final long serialVersionUID = 1L; private String name; private String value; /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(final String name) { this.name = name; } /** * @return the value */ public String getValue() { return value; } /** * @param value the value to set */ public void setValue(final String value) { this.value = value; } 相同的错误)

1 个答案:

答案 0 :(得分:2)

问题出在此处的var属性中:

<p:dataTable value="#{bean.contextParams}" var="param">

#{param}是预定义的EL变量名称之一,还有#{request}#{session}#{header}#{cookie}等,也称为“ { {3}}”。 #{param.foo}基本上会打印request.getParameter("foo"),这实际上是不可变的。您不能在请求参数映射中设置新值。因此是例外。

您需要给它一个不保留的其他名称。例子:

  • <p:dataTable value="#{bean.contextParams}" var="contextParam">
  • <p:dataTable value="#{bean.contextParams}" var="parameter">
  • <p:dataTable value="#{bean.contextParams}" var="p">