2

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:

The jars in my WEB-INF/lib: enter image description here

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>
Community
  • 1
  • 1
vasigorc
  • 502
  • 6
  • 14
  • 1
    http://stackoverflow.com/q/30128395/1391249 – Tiny Dec 21 '15 at 04:00
  • Thank you, TIny, but that would be to easy :-) I have read that post two or three times. What applies to my project is met: using CDI 1.1 with bean-discovery-mode="annotated" (enterprise.context packages used always), GF is not a non-Java EE container and I am not packaging CDI managed beans for JSF views in a JAR (I tried creating the META-INF package and placing an empty beans.xml there too though - didn't help). CDI's spec for default name is also followed if you check the example above. – vasigorc Dec 21 '15 at 04:36
  • Could it be due to this GF bug? https://java.net/jira/browse/GLASSFISH-21166 If yes, what could be a workaround for me? I already have a beans.xml file in WEB-INF. I have also updated the ticket to include a snapshot of the jars in my WEB-INF/lib – vasigorc Dec 21 '15 at 05:12
  • There are a lot of JARs in /WEB-INF/lib which absolutely don't belong there. You should mark server-provided libraries as `provided` in pom. – BalusC Dec 21 '15 at 07:11
  • Thank you, BalusC. I have ran across a similar suggestion here - http://stackoverflow.com/questions/20050266/cdi-deployment-failureweld-001414-bean-name-is-ambiguous?rq=1 I am updating the ticket to include the jar portion of the pom.xml file. Could you please give me some examples of where I should apply this? – vasigorc Dec 21 '15 at 12:24
  • All of javax.* stuff is already provided by a Java EE server. All of maven.* stuff is totally unnecessary. Maven is for build only. – BalusC Dec 21 '15 at 12:29
  • I.e. I have to add the "provided" scope for these artifacts: maven-resources-plugin, javaee-web-api? – vasigorc Dec 21 '15 at 12:34
  • BalusC, thank you. All I did is added provided to javax.servlet-api and everything is back to normal! Would you like to post your comment as an answer? – vasigorc Dec 22 '15 at 22:07

0 Answers0