I’m having trouble displaying my JSF project view -

Asked

Viewed 23 times

0

no error appears and the screen is blank. I believe that it should not be anything very complex to solve but I am new in this language and I’m having difficulty to understand the syntax.

In the view create_group.xhtml:

        <p:outputLabel value="Apelido: "  />

        <p:inputText value="#{sessao.g.nome}" id="edNomeGrupo" />  <br/>


        <p:commandButton value="Entrar" action="#{sessao.cadastrar()}" />
</h:form>

in the bean:

@SessionScoped
@ManagedBean
public class Sessao implements Serializable {

    List<Grupo> grupos;
    Grupo g;

    @ManagedProperty(value = "#{aplicacao}")
    Aplicacao app;

    public Sessao() {

        grupos = new LinkedList<Grupo>();
        g = new Grupo();
    }

    public String cadastrar() {
        grupos.add(g);
        g = new Grupo();

       app.adicinarRegistros(grupos);

        return null;
    }

I’ll post the other bean tbm:

@ApplicationScoped
@ManagedBean
public class Aplicacao {

private List<Grupo> registrados;

List<SelectItem> gruposSelecao;

public Aplicacao() {
        registrados = new LinkedList<Grupo>();
    }

    public List<SelectItem> getGruposSelecao(){

        if(gruposSelecao == null){

            gruposSelecao = new LinkedList<>();

            for(Grupo c: registrados){

                gruposSelecao.add(new SelectItem(c, c.getNome()));
            }

        }

        return gruposSelecao;
    }


  public void adicinarRegistros(List<Grupo> novos) {
        registrados.addAll( novos );
    }
}    

1 answer

0

I believe Nullpointer is occurring. Creates an init() method and notes as @Postconstruct. In the init() method you instantiate your attribute g.

@PostContruct
private void init() {
    g = new Grupo();
}

If I don’t resolve post your complete view so we can help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.