错误渲染视图[dummy.xhtml]:java.lang.NullPointerException

时间:2017-01-27 13:09:34

标签: jsf primefaces

我是JSF的新手,最近我收到了这个错误,我无法解决。我的目的是打开一个对话框,其中有一个选项列表,可以从列表中进行选择,并使用所选元素重新加载数据表。

  

13:47:22,873严重   [javax.enterprise.resource.webcontainer.jsf.context](默认任务-72)   javax.faces.component.UpdateModelException:   javax.el.PropertyNotWritableException:   /forms/bestellungLieferant.xhtml @ 29,29   值= “#{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();
    }
}

我的Stacktrace:

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;
    }
}

欢迎任何提示。

提前致谢!

2 个答案:

答案 0 :(得分:3)

您想要访问辅助bean中的属性。该属性不是getAllAvailableKomponentDualListModelallAvailableKomponentDualListModel,而是komponentenDualListModel

value="#{bestellungLieferantController.komponentDualListModel}"

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

答案 1 :(得分:1)

p:pickList组件value属性中写下这样的内容:

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; 
}