0
I have a problem and I was wondering if you could help me.
I have a CRUD that registers cycles, these cycles can have many courses.
What I wanted to do exactly, is validate the selectsOneRadios when registering a question, ie, choose a cycle in a checkbox and in the next checkbox enable the user to register a question of a course that is of this chosen cycle. It is more or less, check box of State and City.
Follows the code:
Questaobean
@Named
@ViewScoped
public class CadastroUsuarioBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private UsuarioService usuarioService;
@Inject
private GrupoDAO grupoDAO;
@Inject
private CursoDAO cursoDAO;
@Inject
private FormacaoDAO formacaoDAO;
private Usuario usuario;
private List<Grupo> grupos;
private List<Curso> cursos;
private List<Formacao> formacoes;
@PostConstruct
private void init() {
this.limpar();
this.grupos = grupoDAO.buscaPorTodosGrupos();
this.cursos = cursoDAO.buscaPorTodosCursos();
this.formacoes = formacaoDAO.buscaPorTodasFormacoes();
}
@Transactional
public void salvar() throws Exception {
try {
this.usuarioService.salvar(usuario);
FacesUtil
.addSuccessMessage("Pré cadastro efetuado com sucesso. Aguarde a aprovação!");
} catch (IllegalArgumentException e) {
FacesUtil.addErrorMessage("Erro ao tentar realizar o cadastro!");
}
this.limpar();
}
private void limpar() {
this.usuario = new Usuario();
}
public List<Grupo> getGrupos() {
return grupos;
}
public List<Curso> getCursos() {
return cursos;
}
public List<Formacao> getFormacoes() {
return formacoes;
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
DAO:
@SuppressWarnings("unchecked")
public List<Curso> buscarCursoPorCiclo(Long codigo) {
return manager
.createQuery(
"select c from Ciclo c JOIN c.cursos a where c.codigo = ?")
.setParameter(1, codigo).getResultList();
}
Page XHTML:
<h:panelGrid id="cicloPanelGrid" columns="2">
<p:outputLabel value="Ciclo" for="ciclo" style="font-weight:bold" />
<p:selectOneMenu id="ciclo"
value="#{cadastroQuestaoBean.questao.ciclo}"
converter="cicloConverter" required="true"
requiredMessage="Preencha o Ciclo">
<p:ajax event="change" process="@this ciclo" update="curso" />
<f:selectItem itemLabel="Selecione..." />
<f:attribute name="collectionType" value="java.util.ArrayList" />
<f:selectItems value="#{cadastroQuestaoBean.ciclos}" var="ciclo"
itemLabel="#{ciclo.descricao}" itemValue="#{ciclo}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2">
<p:outputLabel value="Curso" for="curso" style="font-weight:bold" />
<p:selectOneMenu id="curso"
value="#{cadastroQuestaoBean.questao.curso}"
converter="cursoConverter" required="true"
requiredMessage="Preencha o curso">
<f:selectItem itemLabel="Selecione..." />
<f:attribute name="collectionType" value="java.util.ArrayList" />
<f:selectItems value="#{cadastroQuestaoBean.cursos}" var="curso"
itemLabel="#{curso.nome}" itemValue="#{curso}" />
</p:selectOneMenu>
</h:panelGrid>
ERROR:
itemLabel="#{curso.nome}": Property 'nome' not found on type com.sisEnade.tcc.modelo.Ciclo
Post all your bean Managed and the course class as well. This will help so that someone can help you find the solution.
– Weslley Tavares
Ready Weslley Tavares.
– Felipe Portela
Where do you define the 'register' bean'?
– Weslley Tavares
What does it feel like? If it’s a layer matter it’s a controller if it’s a matter of calling it, use it in xhtml.
– Felipe Portela
As its error clearly describes, the problem is occurring at the moment that your application makes a call to a certain property of an object, however, you are not able to access this attribute. It would be nice if you post all the classes that are involved in this chain call.
– Weslley Tavares