我有一个带有作业列表的第一个dataTable,对于列表中的每个作业,我不想创建第二个dataTable(在第一个内部),带有触发器这是我的jsf页面:
<p:dataTable id="jobs" var="job" value="#{jobBean.jobList}" rowKey="job.key">
<f:facet name="header">
Jobs List
</f:facet>
<p:column headerText="Name">
#{job.key.name}
</p:column>
<p:column headerText="Group">
#{job.key.group}
</p:column>
<p:column headerText="Triggers">
<p:dataTable id="triggers" var="trigger" value="#{jobBean.triggerList}">
<p:column headerText="Start Time">
#{trigger.startTime}
</p:column>
</p:dataTable>
</p:column>
</p:dataTable>
因此对于每个作业var我都不会有触发器List,这是我的managedBean:
public class JobBean implements Serializable {
@ManagedProperty(value = "#{job}")
private JobDetail job;
private List<Trigger> triggerList;
....
/**
* @param triggerList
* the triggerList to set
*/
public void setTriggerList(List<Trigger> triggerList) {
this.triggerList = triggerList;
}
/**
* @return the triggerList
*/
public List<Trigger> getTriggerList() {
this.get();
return triggerList;
}
private void get(){
FacesContext ctx = FacesContext.getCurrentInstance();
JobDetail jb = ctx.getApplication().evaluateExpressionGet(ctx, "# {job}", JobDetail.class);
this.triggerList = triggerListMap.get(jb.getKey());
}
/**
* @param job
* the job to set
*/
public void setJob(JobDetail job) {
this.job = job;
}
/**
* @return the job
*/
public JobDetail getJob() {
return job;
}
}
get()方法返回一个空指针异常:
引起:java.lang.NullPointerException at tti.frameworkBI.web.JobBean.get(JobBean.java:129)
答案 0 :(得分:0)
最简单的方法是在JobDetails类中声明触发器列表并像这样使用它:
<p:dataTable id="jobs" var="job" value="#{jobBean.jobList}" rowKey="job.key">
<f:facet name="header">
Jobs List
</f:facet>
<p:column headerText="Name">
#{job.key.name}
</p:column>
<p:column headerText="Group">
#{job.key.group}
</p:column>
<p:column headerText="Triggers">
<p:dataTable id="triggers" var="trigger" value="#{job.triggerList}">
<p:column headerText="Start Time">
#{trigger.startTime}
</p:column>
</p:dataTable>
</p:column>
</p:dataTable> code here
答案 1 :(得分:0)
使用findComponent和getRowData()解决:
public List<Trigger> getTriggerList() {
this.get();
return triggerList;
}
private void get() {
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance()
.getViewRoot().findComponent("form:jobs");
JobDetail jb = (JobDetail) dataTable.getRowData();
this.triggerList = this.jobServiceImpl.getAllTriggers(scheduler,
jb.getKey());
}