0

I am developing a web application in JSF. My question is when user enter after authentication the data will be the same means if we have two employee the data display is the same how this problem is solved in program. I import the entity from database and jsf page from entity

This is new for me I am try in PHP but I don't know in JSF.

public EmplController() {
}

public Empl getSelected() {
    return selected;
}

public void setSelected(Empl selected) {
    this.selected = selected;
}

protected void setEmbeddableKeys() {
}

protected void initializeEmbeddableKey() {
}

private EmplFacade getFacade() {
    return ejbFacade;
}

public Empl prepareCreate() {
    selected = new Empl();
    initializeEmbeddableKey();
    return selected;
}

public void create() {
    persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("EmplCreated"));
    if (!JsfUtil.isValidationFailed()) {
        items = null;    // Invalidate list of items to trigger re-query.
    }
}

public void update() {
    persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("EmplUpdated"));
}

public void destroy() {
    persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("EmplDeleted"));
    if (!JsfUtil.isValidationFailed()) {
        selected = null; // Remove selection
        items = null;    // Invalidate list of items to trigger re-query.
    }
}

public List<Empl> getItems() {
    if (items == null) {
        items = getFacade().findAll();
    }
    return items;
}

private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
        setEmbeddableKeys();
        try {
            if (persistAction != PersistAction.DELETE) {
                getFacade().edit(selected);
            } else {
                getFacade().remove(selected);
            }
            JsfUtil.addSuccessMessage(successMessage);
        } catch (EJBException ex) {
            String msg = "";
            Throwable cause = ex.getCause();
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            if (msg.length() > 0) {
                JsfUtil.addErrorMessage(msg);
            } else {
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        }
    }
}

public Empl getEmpl(java.lang.String id) {
    return getFacade().find(id);
}

public List<Empl> getItemsAvailableSelectMany() {
    return getFacade().findAll();
}

public List<Empl> getItemsAvailableSelectOne() {
    return getFacade().findAll();
}

@FacesConverter(forClass = Empl.class)
public static class EmplControllerConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        EmplController controller = (EmplController) facesContext.getApplication().getELResolver().
                getValue(facesContext.getELContext(), null, "emplController");
        return controller.getEmpl(getKey(value));
    }

    java.lang.String getKey(String value) {
        java.lang.String key;
        key = value;
        return key;
    }

    String getStringKey(java.lang.String value) {
        StringBuilder sb = new StringBuilder();
        sb.append(value);
        return sb.toString();
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof Empl) {
            Empl o = (Empl) object;
            return getStringKey(o.getUserName());
        } else {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), Empl.class.getName()});
            return null;
        }
    }

}

    private String username;
private String password;
private String role;
private String value;

public void setRole(String role) {
    this.role = role;
}

public String getRole() {
    return role;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassWord() {
    return password;
}

public void setPassWord(String pass) {
    this.password = pass;
}

public String LogInfo() {
    System.out.println("" + username);
    boolean log = ejbFacade.LogValidate(username, password, role);
    System.out.println("" + log);

    if (log==false) {

        switch (role) {
            case "admin":
                value = "/faces/admin.xhtml?faces-redirect=true";
                break;
            case "employee":
                value = "/faces/employee.xhtml?faces-redirect=true";
                break;
            case "director":                  
                value = "/faces/director.xhtml?faces-redirect=true";
                break;
            case "manager":
                value = "/faces/manager.xhtml?faces-redirect=true";
                break;
            case "simret":
                value = "/faces/simret.xhtml?faces-redirect=true";
                break;
            case "driver":
                value = "/faces/driver.xhtml?faces-redirect=true";
                break;
            case "store":
                value = "/faces/store.xhtml?faces-redirect=true";
                break;

        }
    } else {
        return "/faces/record/List.xhtml?faces-redirect=true";
    }
    return value;
}
 public String logout() {
  HttpSession session = JsfUtil.getSession();
  session.invalidate();
  return "index";
}

I'm expecting when different employee is enter the data will be different but the data will be the same.

Selaron
  • 6,105
  • 4
  • 31
  • 39
ante01
  • 1
  • 1
  • 1
    To me your question appears to be rather unclear. You can increase chances of getting help by editing your question making it a [mcve] and describing the input and actual and expected output. – Selaron Sep 20 '19 at 10:26
  • 1
    I guess his bean is application scoped or he's using static variables. Impossible to answer without a minimal reproducible example because the information and code posted so far is incomplete. Most probably this is a duplicate: https://stackoverflow.com/q/7604810 – BalusC Sep 20 '19 at 11:48

0 Answers0