jeudi 30 juillet 2015

why does me Object become null in JSF 2.2 using primefaces when going from bean to .xhtml

I am building a JSF 2.0 Application using primfaces. I have a managed bean that has several objects for different scenarios. In this particular portion of the application I move from a data table/form to a managed bean with an identification number. I pull the information from the database and even have it in the log. However when I make it to the JSF xhtml page the object values are null and I can't seem to figure out why, any help would be great as I am getting no errors, exceptions, or warnings in the logs and all information seems to point to the loading of the data including the log.

JSF Page that I am coming from... jobs.xhtml (I am using jsf 2.2 and primefaces to build this application) From this page the link specifies a job number to be retrieved and the next bean will retrieve that job based on the job number I have it down to just a button that will take you to the primary method and get the information to the next page...

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://ift.tt/mOIMeg">
<html xmlns="http://ift.tt/lH0Osb"
xmlns:h="http://ift.tt/HjFrZb"
xmlns:f="http://ift.tt/HcrI1S"
xmlns:ui="http://ift.tt/KsEgXx"
xmlns:p="http://ift.tt/HjFrZc">
<body>
    <div style="margin-bottom:350px;">
        <p:column>
            <h:form>
                <h:commandButton id="editProject" action="#{editProjects.getProjectForm()}" value="Edit" />
            </h:form>
        </p:column>
    </div>
</body>
</html>

the mailerproject object class so that you have it for retesting

package objects;

import java.io.Serializable;
import java.util.Date;


public class MailerProject extends Project implements Serializable {

    private static final long serialVersionUID = -2033356999891677741L;
    private String size;
    private String color;
    private String quantity;
    private Date proofDue;
    private Date in_home;
    private Date press_deadline;
    private Date begin;
    private Date end;
    private boolean hosted;
    private String calls_to;
    private String leads_to;
    private String postage;
    private double price = 0;
    private String data;
    private String data_instructions;
    private String mail_house;
    private String notes;

    public MailerProject() {

    }

    public MailerProject(String jobNumber, Date openDate,
            boolean projectClosed, String salesMan, String campaign,
            String status, boolean co_op, boolean compliance, String jobType,
            int medium, int userId, int dealerID, String desc_id, String size, String color,
            String quantity, Date proofDue, Date in_home, Date press_dealine,
            Date begin, Date end, boolean hosted, String calls_to,
            String leads_to, String postage, double price, String data,
            String data_instructions, String mail_house, String notes) {

        super(jobNumber, openDate, projectClosed, salesMan, campaign, status, co_op,
                compliance, jobType, medium, userId, dealerID);

        this.size = size;
        this.color = color;
        this.quantity = quantity;
        this.proofDue = proofDue;
        this.in_home = in_home;
        this.press_deadline = press_dealine;
        this.begin = begin;
        this.end = end;
        this.hosted = hosted;
        this.calls_to = calls_to;
        this.leads_to = leads_to;
        this.postage = postage;
        this.price = price;
        this.data = data;
        this.data_instructions = data_instructions;
        this.mail_house = mail_house;
        this.notes = notes;
    }

}

Super class Project for mailerProject

package  objects;

import java.io.Serializable;
import java.util.Date;

public class Project implements Serializable{

    private static final long serialVersionUID = 3468591497012564082L;
    private int projectId;
    private String jobNumber;
    private Date openDate;
    private boolean projectClosed;
    private String salesMan;
    private String campaign;
    private String status;
    private String jobType;
    private boolean co_op;
    private boolean compliance;
    private int medium;
    private int userId;
    private int dealerID;

    public Project() {
    }

    public Project(String jobNumber, Date openDate, boolean projectClosed,
            String salesMan, String campaign, String status, boolean co_op,
            boolean compliance, String jobType, int medium, int userId,
            int dealerID) {
        this.jobNumber = jobNumber;
        this.openDate = openDate;
        this.projectClosed = projectClosed;
        this.salesMan = salesMan;
        this.campaign = campaign;
        this.status = status;
        this.jobType = jobType;
        this.medium = medium;
        this.userId = userId;
        this.dealerID = dealerID;
    }
}

EditProjects.java the backing bean for the editMailerJob.xhtml which will take in the medium id and the job number the medium id will be used to direct the application to the next page and the job number will be used to retrieve a specific job

package beans;

import java.io.Serializable;
import java.util.Map.Entry;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.RossProjectManagement.rpm.dao.DescriptionDao;
import com.RossProjectManagement.rpm.dao.ProjectDao;
import com.RossProjectManagement.rpm.objects.MailerProject;

@ManagedBean
@ViewScoped
public class EditProjects implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 8453455174655946403L;
private final Log LOG = LogFactory.getLog(this.getClass().getName());

//Editable projects
private MailerProject edit_mailer = new MailerProject();

public int getProjectForm() {
    ProjectDao pdao = new ProjectDao();
    DescriptionDao ddao = new DescriptionDao();

    loadEditMailer(jobNumber, pdao, ddao);

    return 1;
}

public void loadEditMailer() {
    this.edit_mailer = new Mailer("REDJ15061005", new java.util.Date("2015-06-29"),
        false, "RickD", "RickD and the Gang", "new", true, true, "SPEC", 1, 1, 1, 
        "REDJ15061005", "11X17", "SPOT_COLOR", "20,000", new java.util.Date("2015-06-30"), 
        new java.util.Date("2015-07-13"), new java.util.Date("2015-07-06"), new java.util.Date("2015-07-06"), 
        new java.util.Date("2015-07-15"), true, "BDC", "RichardDavy42@gmail.com", "STANDARD", 7500.00, "CONQUEST",
        "NONE", "JS DIRECT", "NONE");
}

public MailerProject getEdit_mailer() {
    return edit_mailer;
}

public void setEdit_mailer(MailerProject edit_mailer) {
    this.edit_mailer = edit_mailer;
}

}

JSF page that I am redirecting to editMailerJob.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb"
xmlns:h="http://ift.tt/HjFrZb"
xmlns:f="http://ift.tt/HcrI1S"
xmlns:ui="http://ift.tt/KsEgXx"
xmlns:p="http://ift.tt/HjFrZc">
<body>
    <div style="margin-bottom: 350px;">
        <h:outputLabel>#{editProjects.edit_mailer}</h:outputLabel>
    </div>
</body>
</html>

The faces-config.xml as minimal as possible...

<?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.2"
              xmlns="http://ift.tt/19L2NlC"
              xmlns:xsi="http://ift.tt/ra1lAU"
              xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1mXF9WB">
    <!-- Here is where we are selecting jobs to edit -->
     <navigation-rule>
        <description>Edit Project</description>
        <from-view-id>/main/jobs.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{editProjects.getProjectForm()}</from-action>
            <from-outcome>1</from-outcome>
            <to-view-id>/main/forms/editMailerJob.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>currentDate</managed-bean-name>
        <managed-bean-class>java.util.Date</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

</faces-config>

The log shows that all of the information has been received and loaded but shows no where that the information has been cleaned or the object made anew. I have tried instantiating the object in different places at different times but that didn't work.

Before I leave the bean the object has value, when I get to the page the object has no value, I don't understand why

I then tried loading the information from different places. I have tried changing the scope of the bean from request to view back to request but no luck, (I thought about doing session but I didn't see the benefit as well as I just couldn't see reasoning to put all of that information into the session).

The problem seems to be revolving directly around the bean itself and the getProjectForm Method because at one point the object is loaded and then it just loses all of its information.

All of my values seem to be correct as far as I can tell but none of the information is loading.

I can't seem to wrap my head around the issue so any help would be greatly appreciated. if any more information is needed just let me know.

I hope all of this helps Let me know if I have forgotten anything.

Aucun commentaire:

Enregistrer un commentaire