I'm new to Java and tried to follow this tutorial. Since it's outdated, I've made some changes to use newer versions:
- Netbeans 14
- Glassfish 6
- Java EE7
- Jakarta Faces 3
- Mojarra 3.0.1
The tutorial consists of a form where a user submits a message and gets the total count. However, when I submit, I get
Any clue of what I'm missing?
Here are the Glassfish logs
When app runs
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#] WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#] WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#] WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType) used for class com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI 1.1!|#] Initializing Soteria 2.0.1 for context '/mavenproject1'|#] Initializing Mojarra 3.0.1 for context '/mavenproject1'|#]
Monitoring jndi:/server/mavenproject1/WEB-INF/faces-config.xml for modifications|#] Loading application [mavenproject1] at [/mavenproject1]|#] mavenproject1 was successfully deployed in 4,055 milliseconds.|#]
When I click submit
/index.xhtml @15,103 value="#{messageView.message.message}": Target Unreachable, identifier 'messageView' resolved to null jakarta.el.PropertyNotFoundException: /index.xhtml @15,103 value="#{messageView.message.message}": Target Unreachable, identifier 'messageView' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:69) at jakarta.faces.component.UIInput.getConvertedValue(UIInput.java:1040) at jakarta.faces.component.UIInput.validate(UIInput.java:955) at jakarta.faces.component.UIInput.executeValidate(UIInput.java:1232) at jakarta.faces.component.UIInput.processValidators(UIInput.java:721) at jakarta.faces.component.UIForm.processValidators(UIForm.java:217) at jakarta.faces.component.UIComponentBase.processValidators(UIComponentBase.java:901) at jakarta.faces.component.UIComponentBase.processValidators(UIComponentBase.java:901) at jakarta.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1254) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:49) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:159) at jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:681) at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:437) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:440) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:174) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:153) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:196) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:88) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:246) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:178) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:118) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:96) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:51) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:510) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:82) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:83) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:34) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:101) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: jakarta.el.PropertyNotFoundException: Target Unreachable, identifier 'messageView' resolved to null at com.sun.el.parser.AstValue.getTarget(AstValue.java:148) at com.sun.el.parser.AstValue.getType(AstValue.java:62) at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:160) at org.jboss.weld.module.web.el.WeldValueExpression.getType(WeldValueExpression.java:93) at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:62) ... 42 more
Here are some of the related files
index.xhtml
<?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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<f:view>
<h:form>
<h:outputLabel value="Message:"/><h:inputText value="#{messageView.message.message}"/>
<h:commandButton action="#{messageView.postMessage}" value="Post Message"/>
</h:form>
</f:view>
</h:body>
</html>
MessageView.java
package my.presentation;
import boundary.MessageFacade;
import entities.Message;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
@Named(value = "messageView")
@RequestScoped
public class MessageView {
@EJB
private MessageFacade messageFacade;
private Message message;
public MessageView() {
this.message = new Message();
}
public Message getMessage(){
return message;
}
public int getMessagesCount(){
return messageFacade.findAll().size();
}
public String postMessage(){
this.messageFacade.create(message);
return "theend";
}
}
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
version="3.0">
</faces-config>
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd"
version="3.0" bean-discovery-mode="annotated">
</beans>
pom.xml
<dependencies>
<dependency>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<!--
Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>