【问题标题】:Error Rendering View[dummy.xhtml]: java.lang.NullPointerException [duplicate]错误渲染视图 [dummy.xhtml]:java.lang.NullPointerException [重复]
【发布时间】:2017-06-13 04:19:16
【问题描述】:

我对 JSF 很陌生,最近我遇到了这个错误,我无法解决。我的意图是打开一个对话框,其中包含一个选择列表,以从列表中进行选择并使用所选元素重新加载数据表。

13:47:22,873 严重 [javax.enterprise.resource.webcontainer.jsf.context](默认任务 72) javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /forms/bestellungLieferant.xhtml @29,29 value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}": 集合操作的非法语法

我的 JSF 页面:

<!DOCTYPE HTML>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<f:view>
    <f:metadata>
        <!-- Start working on a task. Task Id is read internally from
         request parameters and cached in the CDI conversation scope.
    -->

        <f:event type="preRenderView"
            listener="#{camundaTaskForm.startTaskForm()}" />
    </f:metadata>
    <h:head>
        <title>Paket zusammenstellen</title>
    </h:head>
    <h:body>
        <p:dialog id="komponentenAuswahlDialog" header="Komponenten auswählen"
            widgetVar="komponentenAuswahlDialog" modal="true" height="auto"
            width="auto" immediate="true" rendered="true">
            <p:pickList converter="entityConverter"
                id="komponenteAuswahlPickList"
                value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}"
                var="komponente" itemLabel="#{komponente.serienNummer}"
                itemValue="#{komponente.id}" showSourceFilter="true"
                showTargetFilter="true">
                <f:facet name="sourceCaption">Quelle</f:facet>
                <f:facet name="targetCaption">Ziel</f:facet>
            </p:pickList>
            <h:form>
                <p:commandButton update="komponenteTable" value="Auswahl speichern"
                    oncomplete="PF('komponentenAuswahlDialog').hide();" />
            </h:form>
        </p:dialog>
        <h:panelGrid id="paketInformationPG" columns="2" border="1">
            <f:facet name="header">
                <h:outputText value="Paket zusammenstellen" />
            </f:facet>
            <h:outputLabel value="Kunde:" />
            <h:outputText value="#{processVariables['kunde']}" />

            <h:outputLabel value="Betriebssystem:" />
            <h:outputText value="Platzhalter" />

            <h:outputLabel value="Benutzer:" />
            <h:outputText value="#{processVariables['benutzerName']}" />
        </h:panelGrid>
        <h:panelGrid id="komponentenZusammenstellungPG" columns="2" border="1">
            <f:facet name="header">
                <h:panelGrid columns="2">
                    <h:outputText value="Komponenten" />
                    <h:commandButton type="button"
                        onclick="PF('komponentenAuswahlDialog').show();" value="+" />
                </h:panelGrid>
            </f:facet>
            <p:dataTable id="komponenteTable" widgetVar="komponenteTable"
                var="komponente"
                value="#{bestellungLieferantController.komponentenList}">
                <p:column>
                    <f:facet name="header">Typ</f:facet>
                    <h:outputText value="#{komponente.produkt.typ.name}" />
                </p:column>

                <p:column>
                    <f:facet name="header">Bezeichnung</f:facet>
                    <h:outputText value="#{komponente.produkt.name}" />
                </p:column>

                <p:column>
                    <f:facet name="header">SN</f:facet>
                    <h:outputText value="#{komponente.serienNummer}" />
                </p:column>

                <p:column headerText="Kaufdatum">
                    <f:facet name="header">Kaufdatum</f:facet>
                    <h:outputText value="#{komponente.bestellDatum}" />
                </p:column>

                <p:column>
                    <f:facet name="header">Aktion</f:facet>
                    <p:commandLink value="Bearbeiten" />
                    <p:commandLink value="Enfernen" />
                </p:column>
            </p:dataTable>
        </h:panelGrid>
    </h:body>
</f:view>
</html>

我的控制器:

@ManagedBean
@SessionScoped
public class BestellungLieferantController implements Serializable{

    @EJB
    private BestellungFacade bestellungFacade;

    @EJB
    private PaketFacade paketFacade;

    @EJB
    private KomponenteFacade komponenteFacade;

    @EJB
    private BetriebssystemFacade betriebssystemFacade;

    // Komponent-List with added komponent items
    private List<Komponente> komponentenList = new ArrayList<Komponente>();

    private DualListModel<Komponente> komponentenDualListModel;

    public DualListModel<Komponente> getKomponentenDualListModel() {
        return komponentenDualListModel;
    }

    public void setKomponentenDualListModel(DualListModel<Komponente> komponentenDualListModel) {
        this.komponentenDualListModel = komponentenDualListModel;
    }

    public List<Komponente> getKomponentenList() {
        return komponentenList;
    }

    public void setKomponentenList(List<Komponente> komponentenList) {
        LogManager logManager = LogManager.getLogManager();
        Logger rootLogger = logManager.getLogger("DUMMY");
        rootLogger.setLevel(Level.ALL);
        rootLogger.info("KomponentenList");
        this.komponentenList = komponentenList;
    }


    /**
     * Gets the actual Model with the distinct source and 
     * @param targetList
     * @return
     */
    public DualListModel<Komponente> getAllAvailableKomponentDualListModel(){
        List<Komponente> sourceKomponenteList = this.komponenteFacade.getAllAvailableKomponente();
        List<Komponente> sourceKomponenteDistinctList = new ArrayList<Komponente>();

        if (this.komponentenList.size() != 0){
            for(Komponente k : sourceKomponenteList){
                if (!komponentenList.contains(k)){
                    sourceKomponenteDistinctList.add(k);
                }
            }
        } else {
            sourceKomponenteDistinctList = sourceKomponenteList;
        }


//      komponentenDualListModel.setSource(sourceKomponenteDistinctList);
//      komponentenDualListModel.setTarget(komponentenList);

        this.setKomponentenDualListModel(new DualListModel<Komponente>());
        this.getKomponentenDualListModel().setSource(sourceKomponenteDistinctList);
        this.getKomponentenDualListModel().setTarget(this.komponentenList);



        return this.getKomponentenDualListModel();
    }

    public void putSelectionIntoKomponenteList(){
        LogManager logManager = LogManager.getLogManager();
        Logger rootLogger = logManager.getLogger("DUMMY");
        rootLogger.setLevel(Level.ALL);
        rootLogger.info("PutSelectionIntoKomponentList");
        rootLogger.info("KOMPONENTELIST: " + komponentenDualListModel.getTarget());
        this.komponentenList = this.komponentenDualListModel.getTarget();
    }
}

我的堆栈跟踪:

13:47:22,873 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-72) javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /forms/bestellungLieferant.xhtml @29,29 value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}": Illegal Syntax for Set Operation
    at javax.faces.component.UIInput.updateModel(UIInput.java:866)
    at org.primefaces.component.picklist.PickList.updateValue(PickList.java:530)
    at org.primefaces.component.picklist.PickList.validateValue(PickList.java:394)
    at javax.faces.component.UIInput.validate(UIInput.java:982)
    at org.primefaces.component.picklist.PickList.validate(PickList.java:424)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at org.primefaces.component.dialog.Dialog.processValidators(Dialog.java:423)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotWritableException: /forms/bestellungLieferant.xhtml @29,29 value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}": Illegal Syntax for Set Operation
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
    at javax.faces.component.UIInput.updateModel(UIInput.java:832)
    ... 53 more
Caused by: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
    at com.sun.el.parser.AstValue.setValue(AstValue.java:228)
    at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    ... 54 more

我的转换器:

@FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {

    private static Map<Object, String> entities = new WeakHashMap<Object, String>();

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object entity) {
        synchronized (entities) {
            if (!entities.containsKey(entity)) {
                String uuid = UUID.randomUUID().toString();
                entities.put(entity, uuid);
                return uuid;
            } else {
                return entities.get(entity);
            }
        }
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
        for (Entry<Object, String> entry : entities.entrySet()) {
            if (entry.getValue().equals(uuid)) {
                return entry.getKey();
            }
        }
        return null;
    }
}

欢迎任何提示。

提前致谢!

【问题讨论】:

  • 你为什么要这样改标题?

标签: jsf primefaces


【解决方案1】:

您想访问支持 bean 中的属性。该属性不是getAllAvailableKomponentDualListModelallAvailableKomponentDualListModel 而是komponentenDualListModel

value="#{bestellungLieferantController.komponentDualListModel}"

您的 bean 中已经有了 setter 和 getter 方法。但是,您需要在从视图访问它之前调用方法 getAllAvailableKomponentDualListModel()。

【讨论】:

  • 是的。但是在哪里初始化模型呢?我有一个动态选择列表,它将由数据库值填充。因此我需要调用这个方法。
  • 在getAllAvailableKomponentDualListModel()方法中添加@PostConstruct。
  • 当我使用“@PostConstruct”时,这个方法会被调用一次,对吗?如果用户处于这种状态一段时间并且数据库值发生变化,他将无法处理实际数据。我该如何解决这个问题?
  • 通常用户通过调用一个动作与你的网络应用交互。
  • 也许我不准确。我需要实现通知模式吗?
【解决方案2】:

p:pickList组件@​​987654323@属性中这样写:

value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel}"

编辑 只是想看看尝试在这个方法中返回其他东西,如下所示:

@Override 
public Object getAsObject(FacesContext context, UIComponent component, String uuid) { 
for (Entry<Object, String> entry : entities.entrySet()) { 
if (entry.getValue().equals(uuid)) { 
return entry.getKey(); 
} 
} 
return uuid; 
}

【讨论】:

  • 如果你看上面我只有一个值定义。您的语法是用于访问 bean 属性而不是方法。所以需要括号。
  • 去掉括号是正确的,但还不够。
  • 请访问 primefaces 主页以查看方法中没有括号。例如上传方法(文件上传)primefaces.org/showcase/ui/file/upload/basic.xhtml
  • @ArgaPK 对不起,我不知道。谢谢。
  • 对我来说似乎是错误的。为什么这是一个答案?
猜你喜欢
  • 2011-12-08
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
相关资源
最近更新 更多