-1

I am trying to save an object in the database and trying to save it from this error Target Unreachable, 'Movimentacao' returned null, but I am initializing the Movimentacao object in MangedBean.

ManagedBean

@Named
@ViewScoped
public class PesquisaBemBean implements Serializable {

    private static final long serialVersionUID = 1L;

    private Movimentacao movimentacao;

    @PostConstruct
    public void inicializar(){
        this.novo();
    }

    public void novo(){
        this.movimentacao = new Movimentacao();
    }

    /*remaining code with your get and set*/
}

XHTML code to save

    <p:dialog id="movimentacaoDialogo" widgetVar="movimentacaoDialogo" closable="true" header="Movimentação"
        draggable="false" resizable="false" responsive="true" >
        <h:form id="frmMovimentacao">
            <div class="row">
                <div class="col-md-4 form-group">
                    <p:outputLabel value="N° tombamento"/>
                    <p:inputText value="#{pesquisaBemBean.movimentacao.numeroTombamento}"/>
                </div>
                <div class="col-md-8 form-group">
                    <p:outputLabel value="Setor:" />
                    <p:selectOneMenu value="#{pesquisaBemBean.movimentacao.setor}" style="width: 100%">
                        <f:selectItem itemLabel="Selecione" noSelectionOption="true" />
                        <f:selectItems var="setor" value="#{pesquisaBemBean.setores}"
                            itemValue="#{setor}" itemLabel="#{setor.descricao}"/>
                    </p:selectOneMenu>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 form-group">
                    <p:outputLabel value="Estado de Concervação"/>
                    <p:selectOneMenu style="width: 100%" value="#{pesquisaBemBean.movimentacao.estadoConservacao}">
                        <f:selectItem itemLabel="Selecione" noSelectionOption="true" />
                        <f:selectItems var="ec" value="#{pesquisaBemBean.estadoConcervacoes}"
                            itemValue="#{ec}" itemLabel="#{ec.descricao}"/>
                    </p:selectOneMenu>
                </div>
                <div class="col-md-4 form-group">
                    <p:outputLabel value="Data"/>
                    <p:inputText value="#{pesquisaBemBean.movimentacao.data}"/>
                </div>
                <div class="col-md-12 form-group">
                    <p:outputLabel value="Histórico"/>
                    <p:inputText value="#{pesquisaBemBean.movimentacao.historico}"/>
                </div>
            </div>
            <p:commandButton value="Salvar" oncomplete="PF('movimentacaoDialogo').hide()" 
                action="#{pesquisaBemBean.salvarMovimentacao}"
                update=":frmMovimentacao"/>
        </h:form>
    </p:dialog>

I saw that the error is generated by enabling row selection from a dataTable, because I call the same Movimentacao object in the dataTable selection attribute.

DataTable

            <p:dataTable id="movimentacaoTable" var="movimentacao" rows="3" value="#{pesquisaBemBean.listaMovimentacao}"
                emptyMessage="Selecione um bem" paginator="true" paginatorPosition="bottom"
                selectionMode="single" selection="#{pesquisaBemBean.movimentacao}" rowKey="#{movimentacao.id}">

                <p:column headerText="N° tombamento">
                    <h:outputText value="#{movimentacao.numeroTombamento}"/>
                </p:column>
                <p:column headerText="Operacao">
                    <h:outputText value="#{movimentacao.operacao}"/>
                </p:column>
            </p:dataTable>

One solution I found was to create a new variable of type Movimentacao and call it in the DataTable selection. I was wondering if this is the solution or if I can use only the same variable.

error generated

INFORMAÇÕES: javax.el.PropertyNotFoundException: /bem/PesquisaBem.xhtml @128,91 value="#{pesquisaBemBean.movimentacao.setor}": Target Unreachable, 'movimentacao' returned null
javax.el.PropertyNotFoundException: /bem/PesquisaBem.xhtml @128,91 value="#{pesquisaBemBean.movimentacao.setor}": Target Unreachable, 'movimentacao' returned null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at org.primefaces.renderkit.SelectRenderer.findImplicitConverter(SelectRenderer.java:199)
    at org.primefaces.renderkit.SelectRenderer.getOptionAsString(SelectRenderer.java:185)
    at org.primefaces.renderkit.SelectRenderer.doValidateSubmittedValues(SelectRenderer.java:341)
    at org.primefaces.renderkit.SelectRenderer.validateSubmittedValues(SelectRenderer.java:310)
    at org.primefaces.renderkit.SelectOneRenderer.decode(SelectOneRenderer.java:44)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.decode(SelectOneMenuRenderer.java:78)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:832)
    at javax.faces.component.UIInput.decode(UIInput.java:771)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1227)
    at javax.faces.component.UIInput.processDecodes(UIInput.java:676)
    at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:573)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at javax.faces.component.UIForm.visitTree(UIForm.java:381)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:63)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:927)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    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 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'movimentacao' returned null
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:124)
    at org.apache.el.parser.AstValue.getType(AstValue.java:58)
    at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:168)
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 47 more

library versions

Primefaces: 7.0 Jsf: 2.2.13

  • 3
    Possible duplicate of [Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable](https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) – Selaron Aug 22 '19 at 13:13
  • I already searched everywhere. I only know that the PropertyNotFoundException error is raised when I enable row selection of my DataTable. – Clepson Lacerda Aug 22 '19 at 13:32
  • 1
    According to [ask] you should keep track of what you searched and mention the links and why it did not help. Now it looks like you did nothing. That is not a really good incentive for us to help. In addition to this, you are requested (also in [ask]) to create a [mcve]. Your code is not a [mcve]. It is rather difficult for us to help (and we need to and want to help lots of people so we'd ratther not wast time) cheers. – Kukeltje Aug 22 '19 at 13:45
  • There is no property named `object` anywhere in your code snippet. So either the snippet is wrong or the error message is adjusted before putting into question. Please post a real minimal reproducible example ([JSF-targeted hints also here](https://stackoverflow.com/tags/jsf/info)) and don't modify the error message it is throwing. – BalusC Aug 22 '19 at 17:08
  • I rephrased my question, please see. (: – Clepson Lacerda Aug 22 '19 at 18:17
  • There is still no EL expression referring to a proeprty `Movimentacao` with upper case 'M'. Please find and copy/paste the full exception with entire stack trace from your server log plus version information (PF version, Mojarra/Myfaces version etc. Also be sure to include the xhtml fragment causing this exception as BalusC said. – Selaron Aug 23 '19 at 06:32
  • You should put @PostConstruct above your novo function so it will be called automatically after the bean is created. You try to initialize it in your constructor, where you try to initialize the variable before it is created, might work or might be the cause for your error. Ergo use PostConstruct or put the content of the function inside a static block in your Bean (outside of a function) – theMahaloRecords Aug 23 '19 at 09:00
  • I put the variable `movimentacao` in PostConstruct and still the error continues. I added the mistake for you to see. – Clepson Lacerda Aug 23 '19 at 12:02
  • selection="#{pesquisaBemBean.movimentacao} is only needed for a multi selection, then pesquisaBemBean.movimentacao would be a list of movimentacao elements that are selected and a part of pesquisaBemBean.listaMovimentacao – theMahaloRecords Aug 23 '19 at 12:26
  • So you did set a breakpoint and checked if something was setting it to null? @theMahaloRecords: if you put backticks around code in a comment it is shown as such like `selection="#{pesquisaBemBean.movimentacao}` (do ` selection="#{pesquisaBemBean.movimentacao} ` without the spaces inside it – Kukeltje Aug 23 '19 at 12:28
  • I need to get the row object from this table, so I need to use `selection="#{pesquisaBemBean.movimentacao}"`. I saw that whenever I press the Save button gives the error, even if the save method has only one `System.out.println("\n message \n");`. Is the error in commandButton? `` – Clepson Lacerda Aug 23 '19 at 13:04
  • movimentacao is null, so the object isn't in the live cycle anymore after clicking the save button - that's why even a print function gives you an error as it is casted from an object that doesen't exist at the time you call it; Somehow the JSF Lifecycle destroys your bean before your save function is called - do you also get the same error when your bean is SessionScoped ? !use the right annotation import, its from javax.something, maybe your ViewScoped is from the wrong package – theMahaloRecords Aug 27 '19 at 11:36

2 Answers2

0

I found the solution. I added the attribute immediate="true" in commandButton which opens the dialog I use to register the Movimentacao. Another solution was to add the process="@this" attribute also to the commandButton that opens the dialog.

<p:commandButton id="botao" value="Realizar tombamento" disabled="#{pesquisaBemBean.idBem == null}"
                    oncomplete="PF('movimentacaoDialogo').show()" styleClass="btn btn-info custom-btn"
                    immediate="true"
                    actionListener="#{pesquisaBemBean.novo}"/>
  • Mate, why do you have oncomplete show the dialog? did you try with onclick instead and without the immediate? – BugsForBreakfast Aug 23 '19 at 20:57
  • Does the datatable somehow set the property to null when clicking the button? Does the dataTable selection functionality work for you at all? – Selaron Aug 24 '19 at 06:08
-1

You need to have a getter/setter in PesquisaBemBean of the property movimentacao:

public Movimentacao getMovimentacao() {
    return Movimentacao;
}

public void setMovimentacao(Movimentacao movimentacao) {
    this.movimentacao = movimentacao;
}

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

Blarzek
  • 160
  • 12
  • 1
    @theMahaloRecords: why **should** it? And if there are no getters/setters you get different errors – Kukeltje Aug 23 '19 at 08:47