0

I have this JavaBean ClientManagement

package com.pae.controllers;

import com.pae.entities.Client;
import com.pae.entities.User;
import com.pae.serviceDAO.ClientFacade;
import java.io.Serializable;
import java.util.List;
import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;

@ManagedBean
@ViewScoped
public class ClientManagement implements Serializable {

    private List<Client> clientsList;

    @Inject
    private ClientFacade clientDAO;

    @Inject
    private Registration register;

    @PostConstruct
    public void init() {
        clientsList = clientDAO.findAll();
    }

    public List<Client> getClientsList() {
        return clientsList;
    }

    public void setClientsList(List<Client> clientsList) {
        this.clientsList = clientsList;
    }

    public void addClients() {
        clientsList.add(new Client());
    }

    public Boolean validateEmail(String email) {
        String regex = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
        return email.matches(regex);
    }

    public String saveClient() {
        User user = register.getUser();
        clientsList.forEach(client -> {
            boolean validateEmail = validateEmail(client.getClientEmail());
            if (validateEmail) {
                Client newClient = new Client();
                newClient.setName(client.getName());
                newClient.setCompanyName(client.getCompanyName());
                newClient.setWebsite(client.getWebsite());
                newClient.setClientEmail(client.getClientEmail());
                newClient.setUserid(user);
                try {
                    clientDAO.add(newClient);
                    FacesContext ctx = FacesContext.getCurrentInstance();
                    ctx.addMessage(null, new FacesMessage("Successfully added client" + client.getName()));
                } catch (Exception e) {
                    throw new Error(e);
                }
            } else {
                FacesContext ctx = FacesContext.getCurrentInstance();
                ctx.addMessage(null, new FacesMessage("Provided email is invalid"));
            }
        });
        return "../protected/sendEmail.xhtml?faces-redirect=true";
    }

}

Any my ClientFacade.findAll() method

package com.pae.serviceDAO;

import com.pae.entities.Client;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author marci
 */
@Stateless
public class ClientFacade extends AbstractFacade<Client> {

    @PersistenceContext(unitName = "MailSenderAPPPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ClientFacade() {
        super(Client.class);
    }

    public void add(Client client) {
        getEntityManager().persist(client);
    }

    @Override
    public List<Client> findAll(){
        List<Client> clientList = new ArrayList<>();
        List<Client> result = getEntityManager().createNamedQuery("Client.findAll", Client.class).getResultList();

        clientList.addAll(result);
        return clientList;
    }

}

and my index.xhtml file to just for now display data on page, but the only thing I get is #{client.name} nad #{client.idClient} with no values - just plain text. Why I can't see any values? As I read I have to initialize data in method annotated with @PostConstruct and inside that method assign returned list from ClientFacade to my list and use some iterator to show that data on a screen. What am I doing wrong ?

        <ui:repeat var="client" value="#{clientManagement.clientsList}">
            #{client.name}
            #{client.idClient}
        </ui:repeat>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Marcin
  • 102
  • 1
  • 2
  • 9
  • 1
    1: If you don't use a database but a static array, it works? 2:If you don't use a `ui:repeat` it works? 3:If you don't use an EJB it works? 4:If you don't use the CDI `@Inject` in a JSF `@ManagedBean` it works? Please pick a good tutorial and try to create a [mcve]. Do a view-source of the page on the client, what do you see? – Kukeltje Apr 06 '20 at 17:13
  • oh and you mix the scope of CDI with the 'managedbean' of CDI, Lots of things effectively not good in the code, regardles of the issue of the jsf/el not being parsed. – Kukeltje Apr 06 '20 at 17:30
  • Thanks @BalusC reading that article [https://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re](https://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re) make it work. There was some bad things going on with web.xml, now everything works. – Marcin Apr 06 '20 at 17:53

0 Answers0