I have this very weird error. I know why it would usually be caused. But in my case I think something is wrong with the settings of my project. Everything was working fine with this @Named bean before I have added another @Named bean to my project (with a different name). I had some odd logs about this CDI bean missing @Default, @Any or some other annotation. So I deleted it altogether and returned my project to the state when it was working, but it is now complaining about this old (previously working bean) not being found.
This is the @Named bean:
@Named(value = "appointmentFormBean")
@SessionScoped
public class AppointmentFormBean implements Serializable {
private Date selectedDate;
private boolean datePickerActivated = false;
private List<AppointmentWrapper> bookedAlready;
private final Map<String, String> types;
private LocalTime selectedTime;
private String name;
private String email, message, type;
@EJB
@Default
private AppointmentService service;
public AppointmentFormBean() {
bookedAlready = new ArrayList<>();
types = new LinkedHashMap<>(4, (float) 0.75);
selectedDate = localToUtilDate(getNextSuitableDate(now(), isAWeekEnd, nextNotWeekEnd));
}
public AppointmentService getService() {
return service;
}
public void setService(AppointmentService service) {
this.service = service;
}
public Date getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;
setDatePickerActivated(true);
/*
Here will go the logic about checking the status
and the availabilities of the SceduleDay
*/
setBookedAlready(service.findByDate(DateConverters.utilToSql(selectedDate)));
}
public boolean isDatePickerActivated() {
return datePickerActivated;
}
public void setDatePickerActivated(boolean datePickerActivated) {
this.datePickerActivated = datePickerActivated;
}
public List<AppointmentWrapper> getBookedAlready() {
return bookedAlready;
}
public void setBookedAlready(List<AppointmentWrapper> dayAppointments) {
this.bookedAlready = dayAppointments;
}
/*
This will be replaced altogether
As the client doesn't need a list of appointments,
but rather a list of availabilities. The given below
is only a temporary hack
*/
public List<LocalTime> getAvailabilities() {
List<Integer> freeSpots = IntStream.rangeClosed(9, 16).filter(i -> i != 12).boxed().collect(toList());
IntStream takenSpots = new LinkedList<>(getBookedAlready()).stream().mapToInt(wrapper
-> wrapper.getTime().getHour());
freeSpots.removeAll(takenSpots.boxed().collect(toList()));
return freeSpots.stream().map(i -> LocalTime.of(i, 0)).collect(toList());
}
public Map<String, String> getTypes() {
if (types.isEmpty()) {
types.put(getLocalizedLabel("manicure"), "manicure");
types.put(getLocalizedLabel("massage"), "massage");
types.put(getLocalizedLabel("pedicure"), "pedicure");
types.put(getLocalizedLabel("waxing"), "waxing");
}
return types;
}
public LocalTime getSelectedTime() {
return selectedTime;
}
public void setSelectedTime(LocalTime selectedTime) {
this.selectedTime = selectedTime;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String bookAction(){
Appointment candidate = new Appointment();
candidate.setClientName(name);
candidate.setDate(DateConverters.utilToSql(selectedDate));
candidate.setEmail(email);
candidate.setMessage(message);
candidate.setTime(Java8Toolkit.localToSqlTime(selectedTime));
candidate.setType(type);
/*
below will go the logic to request verification
from a stateless EJB for the Appointment. Might as well be
a util method. Surround by if statement.
*/
service.save(candidate);
return "booked";
}
//a convenience method to get a workable date format for the view
public LocalDate localUtilCaller(){
return utilToSql(this.selectedDate).toLocalDate();
}
}
This is an example of how I call it from an .xhtml page:
<p:calendar style="margin-left: 0.75em;" id="calendar" value="#{appointmentFormBean.selectedDate}" locale="fr"
disabledWeekends="true" mindate="today" maxdate="today+90" mode="popup"
pattern="yyyy-MM-dd">
I have read that this may be caused by some issues due to Maven setup and in particular the war-packaging plugin in pom.xml. Here is mine:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>false</archiveClasses>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
I am using Glassfish 4.1.
These are the lines that may be interesting from the stack:
Info: Session event listener threw exception
java.lang.NullPointerException
at org.jboss.weld.servlet.WeldTerminalListener.getSessionContext(WeldTerminalListener.java:65)
at org.jboss.weld.servlet.WeldTerminalListener.sessionDestroyed(WeldTerminalListener.java:57)....
Caused by: javax.el.PropertyNotFoundException: /appointment.xhtml @28,54 value="#{appointmentFormBean.selectedDate}": Target Unreachable, identifier 'appointmentFormBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:133)
at javax.faces.component.UIInput.updateModel(UIInput.java:832)
... 45 more
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'appointmentFormBean' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
at com.sun.el.parser.AstValue.setValue(AstValue.java:226)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 46 more
Edited:
Edited 2:
Am adding all project's dependencies. As you see I am restraining WELD to test scope only, this is related to another issue I had with this project.
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<type>maven-plugin</type>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-mail</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.jglue.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
<version>3.1.3</version>
<exclusions>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.2.2.Final</version>
<scope>test</scope>
</dependency>
</dependencies>