我正在开发一个应该在TableView
中显示X509证书详细信息的项目应用程序。证书文件是DER编码的,并从客户端计算机的特定文件夹加载。当他点击应用程序窗口中的HDD图标时,我调用控制器的handleHDD()
功能来加载证书并在TabeView
上显示其详细信息。
以下是我的控制器中函数handleHDD()
的代码:
@FXML
private void handleHDD() throws CertificateException, IOException, NoSuchProviderException{
String userDir = System.getProperty("user.home");
File folder = new File(userDir +"\\Desktop\\Certificate_Folder");
FilenameFilter filter = new MyFileFilter();
File[] certificates = folder.listFiles(filter);
ObservableList<CertificateModel> data = FXCollections.observableArrayList();
String columnHeader[] = {"Nom","Version","N°série","Algorithme de signature","Emetteur","Valide à partir de","Valide jusqu'au","Objet","Clé publique"};
if (certificates!=null){
int sizeColumns = 9;
for (File file : certificates){
if(file.isFile()){
try{
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream input = new FileInputStream(file);
X509Certificate cert = (X509Certificate)cf.generateCertificate(input);
for (int j = 0; j < sizeColumns; j++) {
TableColumn<CertificateModel, String> col = new TableColumn();
col.setText(columnHeader[j]);
col.setMinWidth(200);
col.setCellValueFactory(new PropertyValueFactory<CertificateModel, String>(columnHeader[j]));
table.getColumns().addAll(col);
}
data.add(new CertificateModel(file.getName().replace(".der", ""), cert.getVersion(),cert.getSerialNumber().toString(16), cert.getSigAlgName(), cert.getIssuerDN().toString(), cert.getNotBefore(), cert.getNotAfter(), cert.getSubjectDN().toString(), cert.getPublicKey().toString()));
table.setItems(data);
}catch (IOException e){
e.printStackTrace();
}
}
}
}
}
还有我的CertificateModel.java
课程:
public class CertificateModel {
private String nom;
private int version;
private String numserie;
private String algosign;
private String emetteur;
private Date validfrom;
private Date validto;
private String objet;
private String clepub;
public CertificateModel(String nom, int type, String numserie, String algosign, String emetteur, Date validfrom, Date validto, String objet, String clepub) {
this.nom = nom;
this.version = type;
this.numserie = numserie;
this.algosign = algosign;
this.emetteur = emetteur;
this.validfrom = validfrom;
this.validto = validto;
this.objet = objet;
this.clepub = clepub;
}
public void setNom(String nom) {
this.nom = nom;
}
public void setType(int type) {
this.version = type;
}
public void setNumserie(String numserie) {
this.numserie = numserie;
}
public void setAlgosign(String algosign) {
this.algosign = algosign;
}
public void setEmetteur(String emetteur) {
this.emetteur = emetteur;
}
public void setValidfrom(Date validfrom) {
this.validfrom = validfrom;
}
public void setValidto(Date validto) {
this.validto = validto;
}
public void setObjet(String objet) {
this.objet = objet;
}
public void setClepub(String clepub) {
this.clepub = clepub;
}
private static final Logger LOG = Logger.getLogger(CertificateModel.class.getName());
public String getNom() {
return nom;
}
public int getType() {
return version;
}
public String getNumserie() {
return numserie;
}
public String getAlgosign() {
return algosign;
}
public String getEmetteur() {
return emetteur;
}
public Date getValidfrom() {
return validfrom;
}
public Date getValidto() {
return validto;
}
public String getObjet() {
return objet;
}
public String getClepub() {
return clepub;
}
public static Logger getLOG() {
return LOG;
}
}
当我在调试模式下检查我的代码时,我可以看到变量中的所有数据都很好但是tableview仍然是空的。
请帮忙!
答案 0 :(得分:1)
如果您确切知道有9列可以更好地为每个列创建一个单独的列,而不是在循环中创建它们。因此,您可以在$current_month = date("n");
$current_day = date("j");
// date of birth
$dob = strtotime("1991-07-26");
$dob_month = date("n", $dob);
$dob_day = date("j", $dob);
if ($current_month == $dob_month) {
if ($current_day == $dob_day) {
echo 'TODAY';
} elseif ($current_day == $dob_day + 1) {
echo 'YESTERDAY';
} elseif($current_day == $dob_day - 1) {
echo 'TOMORROW';
} else {
echo 'IN this month';
}
} elseif ($current_month < $dob_month) {
echo 'In future';
} else {
echo 'Long back';
}
文件中对其进行广告宣传。然后你必须做一些事情:
重构您的模型类,并为那些要在表中显示的值添加.fxml
- s而不是简单的对象,例如:
Property
然后为他们吸气。
以这种方式为每列设置cellValueFactory:
private String nom; ->private StringProperty nom;
private int version; -> private IntegerProperty version
. . .
private Date validfrom; -> private ObjectProperty<Date> validfrom;
. . .
然后它应该有效。
如果您使用这种方式,您的代码将更加清晰,清晰,您可以看到发生了什么。