I have a problem and would like to know if you can help me.
I have a CRUD that registers cycles, these cycles can have many courses.
What I wanted to do exactly, is to validate the selectsOneRadios when registering an issue, that is choose a cycle in a check box and the next check box will allow the user to register a question of one course of that chosen cycle. It's more or less, check box for State and City.
Follow 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();
}
XHTML Page:
<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="# {course.name}": Property 'name' not found on type com.sisEnade.tcc.Cycle