我想知道为什么我在bean方法中得到空指针。在我的前端,我正在关注价值adp.domain.elementsDomain,因为标签正在屏幕上正确显示。 这是我的前线:
<c:forEach items="#{atributosDaPesquisaBean.atributosDaPesquisaList}" var="adp" varStatus="loop">
<h:panelGrid columns="2" cellpadding="20">
<h:outputText value="#{adp.dominio.nome}"/>
<p:selectManyCheckbox id="gridQueryResult" layout="grid" columns="2">
<f:selectItems value="#{adp.dominio.elementosDominio}" var="elemento" itemLabel="#{elemento.label}" itemValue="#{elemento}" />
<f:ajax listener="#{atributosDaPesquisaBean.incluiNaPesquisa(elemento)}"/>
</p:selectManyCheckbox>
</h:panelGrid>
</c:forEach>
这是我的豆子:
@ManagedBean
@SessionScoped
public class AtributosDaPesquisaBean {
private List<AtributosDaPesquisa> atributosDaPesquisaList;
@PostConstruct
public void init() {
AtributosDaPesquisaDAO adpDao = new AtributosDaPesquisaDAO();
atributosDaPesquisaList = adpDao.buscaPorRelatorio(relatorio.getCodigo());
atributosDaPesquisaList.forEach(adp -> adp.setaClausulaDeData());
for(AtributosDaPesquisa adp: atributosDaPesquisaList){
if(adp.isEhDominio()){
List<ElementoDominio> elementosDominio = adp.getDominio().getElementosDominio();
elementosDominio.forEach(elemento -> elemento.setEstaNaPesquisa(false));
}
}
}
public void incluiNaPesquisa(ElementoDominio elemento){
//here elemento comes as null. Why?
elemento.setEstaNaPesquisa(true);
}
}
这些是我的模特:
@Entity
@Table(name = "tbl_atributosdapesquisa")
public class AtributosDaPesquisa {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "atr_codigo")
private Long codigo;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "tbl_dominio_dom_codigo", referencedColumnName = "dom_codigo")
private Dominio dominio;
//others columns
//getters and setters
}
其他型号:
@Entity
@Table(name = "tbl_dominio")
public class Dominio {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "dom_codigo")
private Long codigo;
@Column(name="dom_nome", nullable = false)
private String nome;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "dominio")
private List<ElementoDominio> elementosDominio;
//getters and setters
}
最后:
@Entity
@Table(name = "tbl_elemento_dominio")
public class ElementoDominio {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ele_dom_codigo")
private Long codigo;
@Column(name="ele_dom_label", nullable = false)
private String label;
@Column(name="ele_dom_esta_na_pesquisa", nullable = false)
private boolean estaNaPesquisa;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "dom_codigo", nullable = false)
private Dominio dominio;
//getters and setters
}
在我的方法'incluiNaPesquisa'中,它以null为参数。我不知道自我的屏幕渲染列表并显示每个标签以来的原因。如果我发送AtributoDaPesquisa作为参数,我没有收到空指针,而是对象。