2016-12-29 74 views
0

我收到java.io.IOException:java.lang.NullPointerException:參數錯誤:參數url爲null。Primefaces 6和Content Flow錯誤

XHTML文件:

<p:dataTable var="vehicleTransactionList" value="#{viewCompanyManagedBean.vehicleTransactionList}"> 
 
<p:column headerText="#{messages.saptrn}"> 
 
<h:outputText value="#{vehicleTransactionList.vehicleTransactionId}" /> 
 
</p:column> 
 
<p:column headerText="#{messages.scalepics}"> \t 
 
<p:contentFlow value="#{viewCompanyManagedBean.vehicleTransactionList}" var="newimage"> 
 
<p:graphicImage value="#{newimage.imageLocations}" styleClass="content" /> 
 
<div class="caption">#{newimage.imageLocations}</div> 
 
</p:contentFlow> 
 
</p:column> 
 
</p:dataTable>

的錯誤是在第二列#{newimage.imageLocations}

管Bean:

package com.company.beans; 
 

 
import com.company.entities.Company; 
 

 
import com.company.entities.Scale; 
 
import com.company.entities.ScaleMeasurement; 
 
import com.company.entities.VehicleTransaction; 
 
import com.company.services.db.ScaleMeasurementService; 
 
import com.company.services.db.ScaleService; 
 

 
import java.io.IOException; 
 
import java.net.UnknownHostException; 
 
import java.text.DateFormat; 
 
import java.text.ParseException; 
 
import java.text.SimpleDateFormat; 
 
import java.util.ArrayList; 
 
import java.util.Date; 
 
import java.util.List; 
 
import java.util.ResourceBundle; 
 
import java.util.logging.Level; 
 
import java.util.logging.Logger; 
 

 
import javax.annotation.PostConstruct; 
 
import javax.faces.application.FacesMessage; 
 
import javax.faces.bean.ManagedBean; 
 
import javax.faces.bean.RequestScoped; 
 
import javax.faces.bean.ViewScoped; 
 
import javax.faces.context.FacesContext; 
 
import javax.servlet.http.HttpServletRequest; 
 

 
import org.jsoup.Jsoup; 
 
import org.jsoup.nodes.Document; 
 
import org.jsoup.nodes.Element; 
 
import org.primefaces.event.SelectEvent; 
 

 
import sunw.io.Serializable; 
 

 
@SuppressWarnings("deprecation") 
 
@ManagedBean 
 
@ViewScoped 
 
public class ViewCompanyManagedBean implements Serializable { 
 
\t static Logger webRecySys = null; 
 
    static { 
 
    \t webRecySys = Logger.getLogger("com.company.webRecySys");  \t 
 
    } 
 
\t 
 
\t public ViewCompanyManagedBean() { 
 
\t \t 
 
\t } 
 
\t @PostConstruct 
 
\t public void populateCompanyData() { 
 
\t \t prepareData(new Date()); 
 
\t \t 
 
     images = new ArrayList<String>(); 
 
     for (int i = 1; i <= 7; i++) { 
 
      images.add("file_" + i + ".jpg"); 
 
     } 
 
\t } 
 
\t @PostConstruct 
 
\t public void onDateSelect(SelectEvent event) throws UnknownHostException { 
 
\t \t SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); 
 
\t \t String date = format.format(event.getObject()); 
 
\t \t try { 
 
\t \t \t Date selectedDate = format.parse(date); 
 
\t \t \t prepareData(selectedDate); \t \t \t \t \t \t \t 
 
\t \t } catch (ParseException e) { 
 
\t \t \t e.printStackTrace(); 
 
\t \t } 
 
\t \t FacesContext facesContext = FacesContext.getCurrentInstance(); 
 
\t \t facesContext.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected",format.format(event.getObject()))); 
 
\t } 
 
\t 
 
\t private void prepareData(Date forData) { 
 
\t \t ScaleService ss = new ScaleService(); 
 
\t \t ScaleMeasurementService sms = new ScaleMeasurementService(); 
 
\t \t Scale right = ss.find(getRightScale()); 
 
\t \t Scale left = ss.find(getLeftScale()); 
 
\t \t this.measurements = sms.getMeasurementForScale(right,forData); 
 
\t \t this.measurements.addAll(sms.getMeasurementForScale(left,forData)); 
 
\t \t SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy"); 
 
\t \t this.fileName = "Shredder_Measurements_"+ sdf.format(forData); 
 
\t \t for (ScaleMeasurement s : measurements) { 
 
\t \t \t if (s.getScale().getScaleId().equalsIgnoreCase(rightScale)) { 
 
\t \t \t \t this.rightScaleMeasurementSum += s.getMeasurement(); 
 
\t \t \t } 
 
\t \t \t if (s.getScale().getScaleId().equalsIgnoreCase(leftScale)) { 
 
\t \t \t \t this.leftScaleMeasurementSum += s.getMeasurement(); 
 
\t \t \t } 
 
\t \t } 
 
\t \t vehicleTransactionList = getVehicleTransactionList(sdf.format(forData) , (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()); 
 
\t } 
 
\t 
 
\t 
 
\t private ArrayList<VehicleTransaction> getVehicleTransactionList(String fileDateFormat,HttpServletRequest request) { 
 
\t \t 
 
\t \t ResourceBundle resourceb = ResourceBundle.getBundle("com.company.messages.image"); 
 
\t \t String imgRootPath = resourceb.getString("imagerootpath"); 
 
\t \t 
 
\t \t ArrayList<VehicleTransaction> images = new ArrayList<VehicleTransaction>(); 
 
\t \t String name = request.getLocalName(); 
 
\t \t if (name != null) { 
 
\t \t \t if (name.startsWith("0")) { 
 
\t \t \t \t name = "localhost"; 
 
\t \t \t } 
 
\t \t } 
 
\t \t else { 
 
\t \t \t name = "localhost"; 
 
\t \t } 
 

 
\t \t Scale scale = new ScaleService().find("01"); 
 
\t \t Company c = new ScaleService().getCompanyFromScale(scale); 
 
\t \t String companyName = c.getCompanyName().trim().replace(" ", "_"); \t \t 
 
\t \t String URL = "http://"+name+":"+request.getLocalPort()+imgRootPath+"/"+companyName+"/"+fileDateFormat+"/"; 
 
\t \t 
 
\t \t ArrayList<String> picUrls = new ArrayList<String>(); \t \t 
 
\t \t Document doc; 
 
\t \t try { 
 
\t \t \t doc = Jsoup.connect(URL).get(); 
 
\t \t \t for (Element file : doc.select("a")) { 
 
\t \t \t \t String urlPathToFile = file.attr("href"); 
 
\t \t \t \t String fileName = file.text(); 
 
\t \t \t \t if (urlPathToFile.endsWith(".jpg") && fileName.endsWith(".jpg")) { 
 
\t \t \t \t \t String picUrl = "http://"+name+":"+request.getLocalPort()+imgRootPath+"/"+companyName+"/"+fileDateFormat+"/"+fileName; 
 
\t \t \t \t \t 
 
\t \t \t \t \t picUrls.add(picUrl); \t \t \t \t \t 
 
\t \t \t \t } 
 
\t \t  } 
 
\t \t } catch (IOException e) { 
 
\t \t \t webRecySys.logp(Level.WARNING, this.getClass().getCanonicalName() , "getAllImagesList", "Cannot get list of Images: "+e.getMessage()); 
 
\t \t } \t 
 
\t \t ArrayList<String> vehicleTransactionIdList = getVehicleTransactionIds(picUrls); 
 
\t \t 
 
\t \t for (String vehicleTransactionId : vehicleTransactionIdList) { 
 
\t \t \t ArrayList<String> imagesForTransaction = getVehicleTransaction(vehicleTransactionId,picUrls); 
 
\t \t \t VehicleTransaction s = new VehicleTransaction(imagesForTransaction, vehicleTransactionId); 
 
\t \t \t images.add(s); 
 
\t \t } 
 
\t \t 
 
\t \t return images; 
 
\t } 
 
\t private ArrayList<String> getVehicleTransaction(String vehicleTransactionId,ArrayList<String> picUrls) { 
 
\t \t ArrayList<String> imagesForTransaction = new ArrayList<String>(); 
 
\t \t for (String url : picUrls) { 
 
\t \t \t if (url.contains(vehicleTransactionId)) { 
 
\t \t \t \t imagesForTransaction.add(url); 
 
\t \t \t } 
 
\t \t } 
 
\t \t return imagesForTransaction; 
 
\t } 
 
\t 
 
\t private ArrayList<String> getVehicleTransactionIds(ArrayList<String> picUrls) { 
 
\t \t ArrayList<String> vehicleTransactionIds = new ArrayList<String>(); 
 
\t \t for (String pic : picUrls) { 
 
\t \t \t String vehicleTransactionId = pic.substring(pic.lastIndexOf("/")+1); 
 
\t \t \t vehicleTransactionId = vehicleTransactionId.substring(0,vehicleTransactionId.indexOf("_")); 
 
\t \t \t if (!existsInArl(vehicleTransactionId,vehicleTransactionIds)) { 
 
\t \t \t \t vehicleTransactionIds.add(vehicleTransactionId); 
 
\t \t \t } 
 
\t \t } 
 
\t \t return vehicleTransactionIds; 
 
\t } 
 
\t private boolean existsInArl (String s , ArrayList<String> arl) { 
 
\t \t boolean exists = false; 
 
\t \t for (String c : arl) { 
 
\t \t \t if (c.equalsIgnoreCase(s)) { 
 
\t \t \t \t exists = true; 
 
\t \t \t } 
 
\t \t } 
 
\t \t return exists; 
 
\t } 
 
\t 
 
\t public Date getDate() { 
 
\t \t return date; 
 
\t } 
 

 
\t public void setDate(Date date) { 
 
\t \t this.date = date; 
 
\t } 
 

 
\t public List<ScaleMeasurement> getMeasurements() { 
 
\t \t return measurements; 
 
\t } 
 
\t public void setMeasurements(List<ScaleMeasurement> measurements) { 
 
\t \t this.measurements = measurements; 
 
\t } 
 
\t public String getFileName() { 
 
\t \t return fileName; 
 
\t } 
 
\t public void setFileName(String fileName) { 
 
\t \t this.fileName = fileName; 
 
\t } 
 
\t public List<String> getImages() { 
 
\t \t return images; 
 
\t } 
 
\t public void setImages(List<String> images) { 
 
\t \t this.images = images; 
 
\t } \t 
 
\t public String getRightScale() { 
 
\t \t return rightScale; 
 
\t } 
 
\t public void setRightScale(String rightScale) { 
 
\t \t this.rightScale = rightScale; 
 
\t } 
 
\t public String getLeftScale() { 
 
\t \t return leftScale; 
 
\t } 
 
\t public void setLeftScale(String leftScale) { 
 
\t \t this.leftScale = leftScale; 
 
\t } 
 
\t public int getRightScaleMeasurementSum() { 
 
\t \t return rightScaleMeasurementSum; 
 
\t } 
 
\t public void setRightScaleMeasurementSum(int rightScaleMeasurementSum) { 
 
\t \t this.rightScaleMeasurementSum = rightScaleMeasurementSum; 
 
\t } 
 
\t public int getLeftScaleMeasurementSum() { 
 
\t \t return leftScaleMeasurementSum; 
 
\t } 
 
\t public void setLeftScaleMeasurementSum(int leftScaleMeasurementSum) { 
 
\t \t this.leftScaleMeasurementSum = leftScaleMeasurementSum; 
 
\t } 
 
\t public ArrayList<VehicleTransaction> getVehicleTransactionList() { 
 
\t \t return vehicleTransactionList; 
 
\t } 
 
\t public void setVehicleTransactionList(
 
\t \t \t ArrayList<VehicleTransaction> vehicleTransactionList) { 
 
\t \t this.vehicleTransactionList = vehicleTransactionList; 
 
\t } 
 

 
\t // Used for Calendar 
 
\t private Date date; 
 
\t // Used for Shredder Measurements \t 
 
\t private List<ScaleMeasurement> measurements = new ArrayList<ScaleMeasurement>(); 
 
\t private String fileName; 
 
\t private String rightScale = "02"; 
 
\t private String leftScale = "03"; 
 
\t private int rightScaleMeasurementSum; 
 
\t private int leftScaleMeasurementSum; 
 
\t 
 
\t // Used for Pictures 
 
    private List<String> images; 
 
    private ArrayList<VehicleTransaction> vehicleTransactionList = new ArrayList<VehicleTransaction>(); 
 
    
 

 
\t private static final long serialVersionUID = 7449888248791054139L; 
 
}

VehicleTransaction POJO的:

package com.company.entities; 
 

 
import java.util.ArrayList; 
 

 
public class VehicleTransaction { 
 
\t public VehicleTransaction() { 
 
\t \t 
 
\t } 
 
\t public VehicleTransaction(ArrayList<String> imageLocations, String vehicleTransactionId) { 
 
\t \t super(); 
 
\t \t this.imageLocations = imageLocations; 
 
\t \t this.vehicleTransactionId = vehicleTransactionId; 
 
\t } 
 
\t public ArrayList<String> getImageLocations() { 
 
\t \t return imageLocations; 
 
\t } 
 
\t public void setImageLocations(ArrayList<String> imageLocations) { 
 
\t \t this.imageLocations = imageLocations; 
 
\t } 
 
\t public String getVehicleTransactionId() { 
 
\t \t return vehicleTransactionId; 
 
\t } 
 
\t public void setVehicleTransactionId(String vehicleTransactionId) { 
 
\t \t this.vehicleTransactionId = vehicleTransactionId; 
 
\t } 
 
\t private ArrayList<String> imageLocations; 
 
\t private String vehicleTransactionId; 
 
}

什麼是我的錯?

回答

1

解決 - 正確的XHTML代碼是:

<p:column headerText="#{messages.scalepics}"> \t 
 
<p:contentFlow value="#{vehicleTransactionList.imageLocations}" var="images"> 
 
<p:graphicImage value="#{images}" styleClass="content" /> 
 
<div class="caption">#{images}</div> 
 
</p:contentFlow> 
 
</p:column>

儘管錯誤代碼是:

<p:contentFlow value="#{viewCompanyManagedBean.vehicleTransactionList}" var="newimage"> 
 
<p:graphicImage value="#{newimage.imageLocations}" styleClass="content" /> 
 
<div class="caption">#{newimage.imageLocations}</div>

+0

護理添加一些評論什麼該區別是什麼?所以其他人不必做手動'差異' – Kukeltje

+0

#{newimage.imageLocations}
Mitsos