0

I've been following this tutorial to integrate spring-boot with primefaces

However I got this error when trying to acces the backing bean:

Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier [clientsView] resolved to null

I did search some answers with this problem but still not figured out what is the problem.

This is my xhtml web page:

<?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://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>New Client</title>
</h:head>

<h:body>

    <script type="text/javascript">
        //<![CDATA[
        /**
         * Faces Validator
         */
        PrimeFaces.validator['client.emailValidator'] = {

            pattern : /\S+@\S+/,

            validate : function(element, value) {
                //use element.data() to access validation metadata, in this case there is none.
                if (!this.pattern.test(value)) {
                    throw {
                        summary : 'Validation Error',
                        detail : value + ' is not a valid email.'
                    }
                }
            }
        };

        /**
         * Bean validator
         */
        PrimeFaces.validator['Email'] = {

            pattern : /\S+@\S+/,

            MESSAGE_ID : 'org.primefaces.examples.validate.email.message',

            validate : function(element, value) {
                var vc = PrimeFaces.util.ValidationContext;

                if (!this.pattern.test(value)) {
                    var msgStr = element.data('p-email-msg'), msg = msgStr ? {
                        summary : msgStr,
                        detail : msgStr
                    } : vc.getMessage(this.MESSAGE_ID);

                    throw msg;
                }
            }
        };
        //]]>
    </script>


    <h:form id="Client">

        <p:panel header="Adsim">
            <h:panelGrid columns="2" cellpadding="4">
                <h:outputText value="Name: " />
                <p:inputText id="name" value="#{clientsView.name}" />

                <h:outputText value="Adress: " />
                <p:inputText id="adress" value="#{clientsView.adress}" />

                <p:outputLabel for="phone" value="Phone:" />
                <p:inputMask id="phone" value="#{maskView.phone}"
                    mask="(999) 999-9999" />

                <h:outputLabel for="email1" value="Email:" />
                <p:inputText id="email1" value="#{clientsView.email}">
                    <f:validateRegex
                        pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                </p:inputText>
                <p:message for="email1" display="tooltip" />
                <h:outputText value="#{clientsView.email}" />

                <p:commandButton id="submit" value="Submit"
                    action="#{clientsView.save}" update="confirmation"
                    icon="pi pi-save" oncomplete="PF('greetingDialog').show()" />
            </h:panelGrid>
        </p:panel>

        <p:dialog header="Confirmation" widgetVar="confirmationDialog"
            modal="true" resizable="false">
            <h:panelGrid id="confirmation" columns="1" cellpadding="4">
                <h:outputText value="#{clientsView.showDialog()}" />
            </h:panelGrid>
        </p:dialog>

    </h:form>
</h:body>
</html>

And this is the backing bean:

package com.goinside.view;

import javax.annotation.PostConstruct;
import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;

import com.goinside.bo.ClientBO;
import com.goinside.service.ClientService;

import lombok.Getter;
import lombok.Setter;

@Named
@Getter
@Setter
public class ClientsView {

    private String name;
    private String adress;
    private String phone;
    private String email;

    @Autowired
    private ClientService clientService;
    private ClientBO clientBO;

    @PostConstruct
    public void init() {
        clientBO = new ClientBO();
    }

    public void save() {
        clientBO.setName(name);
        clientBO.setEmail(email);
        clientBO.setAdress(adress);
        this.clientService.save(clientBO);
    }

    public String showGreeting() {
        return "New client saved succesfuly!";
    }
}

Looks like it has to do with something related to use of CDI @Named annotation but I don't know exactly what it is.

This is the project structure:

barbsan
  • 3,238
  • 11
  • 18
  • 27
Rômulo Sorato
  • 1,025
  • 4
  • 11
  • 19
  • So it works if you change all the `p:input*` components to `h:input*` ones? And it works if you use primefaces without spring-boot? And if you don't include the email validator in javascript? And posting errors in searchengines helps! – Kukeltje Jul 22 '19 at 07:17
  • Still not work with the suggestions,the idea is to use with spring boot.I did search before , but none of the answers help.Thanks! – Rômulo Sorato Jul 23 '19 at 03:05
  • The duplicate with 99% certainty does. – Kukeltje Jul 23 '19 at 03:53

0 Answers0