Skip to Main Content

Debug output not appearing in Glassfish log

258800a3-86d0-4e2c-93f8-798ae8964b79Jun 20 2020 — edited Jun 20 2020

My debugging output is not going to the Glassfish log - trying to figure out why. I have the following class, auto-generated by Netbeans:

package com.technojeeves.tj.jsf;

import com.technojeeves.tj.entity.Job;

import com.technojeeves.tj.jsf.util.JsfUtil;

import com.technojeeves.tj.jsf.util.PaginationHelper;

import com.technojeeves.tj.session.JobFacade;

import java.io.Serializable;

import java.util.ResourceBundle;

import javax.ejb.EJB;

import javax.inject.Named;

import javax.enterprise.context.SessionScoped;

import javax.faces.component.UIComponent;

import javax.faces.context.FacesContext;

import javax.faces.convert.Converter;

import javax.faces.convert.FacesConverter;

import javax.faces.model.DataModel;

import javax.faces.model.ListDataModel;

import javax.faces.model.SelectItem;

@Named("jobController")

@SessionScoped

public class JobController implements Serializable {

    private Job current;

    private DataModel items = null;

    @EJB

    private com.technojeeves.tj.session.JobFacade ejbFacade;

    private PaginationHelper pagination;

    private int selectedItemIndex;

    public JobController() {

    }

    public Job getSelected() {

        if (current == null) {

            current = new Job();

            selectedItemIndex = -1;

        }

        return current;

    }

    private JobFacade getFacade() {

        return ejbFacade;

    }

    public PaginationHelper getPagination() {

        if (pagination == null) {

            pagination = new PaginationHelper(10) {

                @Override

                public int getItemsCount() {

                    return getFacade().count();

                }

                @Override

                public DataModel createPageDataModel() {

                    return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));

                }

            };

        }

        return pagination;

    }

    public String prepareList() {

        recreateModel();

        //DEBUG

        System.out.println("Preparing to list Jobs");

        return "List";

    }

    public String prepareView() {

        current = (Job) getItems().getRowData();

        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();

        return "View";

    }

    public String prepareCreate() {

        current = new Job();

        selectedItemIndex = -1;

        return "Create";

    }

    // Testing by goose

    public String jobsFromTaxYear() {

        return "jobsFromTaxYearResponse";

    }

    public String create() {

        try {

            getFacade().create(current);

            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/resources/Bundle").getString("JobCreated"));

            return prepareCreate();

        } catch (Exception e) {

            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/resources/Bundle").getString("PersistenceErrorOccured"));

            return null;

        }

    }

    public String prepareEdit() {

        current = (Job) getItems().getRowData();

        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();

        return "Edit";

    }

    public String update() {

        try {

            getFacade().edit(current);

            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/resources/Bundle").getString("JobUpdated"));

            return "View";

        } catch (Exception e) {

            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/resources/Bundle").getString("PersistenceErrorOccured"));

            return null;

        }

    }

    public String destroy() {

        current = (Job) getItems().getRowData();

        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();

        performDestroy();

        recreatePagination();

        recreateModel();

        return "List";

    }

    public String destroyAndView() {

        performDestroy();

        recreateModel();

        updateCurrentItem();

        if (selectedItemIndex >= 0) {

            return "View";

        } else {

            // all items were removed - go back to list

            recreateModel();

            return "List";

        }

    }

    private void performDestroy() {

        try {

            getFacade().remove(current);

            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/resources/Bundle").getString("JobDeleted"));

        } catch (Exception e) {

            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/resources/Bundle").getString("PersistenceErrorOccured"));

        }

    }

    private void updateCurrentItem() {

        int count = getFacade().count();

        if (selectedItemIndex >= count) {

            // selected index cannot be bigger than number of items:

            selectedItemIndex = count - 1;

            // go to previous page if last page disappeared:

            if (pagination.getPageFirstItem() >= count) {

                pagination.previousPage();

            }

        }

        if (selectedItemIndex >= 0) {

            current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);

        }

    }

    public DataModel getItems() {

        if (items == null) {

            items = getPagination().createPageDataModel();

        }

        return items;

    }

    private void recreateModel() {

        items = null;

    }

    private void recreatePagination() {

        pagination = null;

    }

    public String next() {

        getPagination().nextPage();

        recreateModel();

        return "List";

    }

    public String previous() {

        getPagination().previousPage();

        recreateModel();

        return "List";

    }

    public SelectItem[] getItemsAvailableSelectMany() {

        return JsfUtil.getSelectItems(ejbFacade.findAll(), false);

    }

    public SelectItem[] getItemsAvailableSelectOne() {

        return JsfUtil.getSelectItems(ejbFacade.findAll(), true);

    }

    public Job getJob(java.lang.Integer id) {

        return ejbFacade.find(id);

    }

    @FacesConverter(forClass = Job.class)

    public static class JobControllerConverter implements Converter {

        @Override

        public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {

            if (value == null || value.length() == 0) {

                return null;

            }

            JobController controller = (JobController) facesContext.getApplication().getELResolver().

                    getValue(facesContext.getELContext(), null, "jobController");

            return controller.getJob(getKey(value));

        }

        java.lang.Integer getKey(String value) {

            java.lang.Integer key;

            key = Integer.valueOf(value);

            return key;

        }

        String getStringKey(java.lang.Integer 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 Job) {

                Job o = (Job) object;

                return getStringKey(o.getId());

            } else {

                throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Job.class.getName());

            }

        }

    }

}

The prepareList method is obviously doing its work as the Jobs list, but I've never seen that System.out.println("Preparing to list Jobs"); have any effect. Why is that?

Comments
Post Details
Added on Jun 20 2020
0 comments
21 views