Method with jsf + output Parameter

Asked

Viewed 156 times

0

How I can pass a parameter to a method and at the same time return the method value with output?

Example.

//Bean
public String getResposta(String ok){
    return ok;
}

//pagina

<h:outputLabel value="#{bean.resposta('RespostaParaRetornar')}">

how do I get the same effect of this syntax in jsf? or how do I make it work. NOTE: I do not want to pass the parameter in commandButton, I need it in outputText or outPutLabel.

Using this example syntax does not work.

JSF accuses Syntax error. and on the page launches Exception.javax.el.Methodnotfoundexception:

Bean Complete.

package br.com.so.bean;

import java.util.List;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import br.com.so.modelo.Questao;

@ManagedBean
@SessionScoped
public class SimuladoRealizadoBean {

    private Map<Long, String> mapaAuxiliar;
    private List<Questao> questoes;
    private String resposta;

    public Map<Long, String> getMapaAuxiliar() {
        return mapaAuxiliar;
    }

    public void setMapaAuxiliar(Map<Long, String> mapaAuxiliar) {
        this.mapaAuxiliar = mapaAuxiliar;
    }

    public List<Questao> getQuestoes() {
        return questoes;
    }

    public void setQuestoes(List<Questao> questoes) {
        this.questoes = questoes;
    }

    public String getResposta(String parametro) {

//      FacesContext facesContext = FacesContext.getCurrentInstance();
//      Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap();
//
//      if (params.get("id") != null) {
//          String questaoID = params.get("id");
//          System.out.println(mapaAuxiliar.size());
//          System.out.println(questaoID);
//          if (questaoID != null) {
//              questaoID = questaoID.trim();
//              Long id = Long.parseLong(questaoID);
//              return this.mapaAuxiliar.get(id);
//          }
//      }
//      
//      return null;

        return parametro;
    }

}

//XHTML

<h:form id="formulario"
            rendered="#{simuladoRealizadoBean.questoes != null}">
            <p:dataList value="#{simuladoRealizadoBean.questoes}" var="q"
                type="unordered" rowIndexVar="qi" itemType="none" paginator="true"
                rows="1" styleClass="paginated">
                <div style="padding: 5px;">
                    <p:outputLabel value="#{q.texto}"
                        styleClass="textoJustificado-centro" />
                    <br />
                    <p:outputLabel value="#{q.referenciaTexto}"
                        style="color:black; float:right; font-size: 12px;" />
                    <br /> <br />
                    <p:outputLabel value="(#{q.disciplina.nome})" />
                    <br /> <br />
                    <p:outputLabel value="#{qi+1}) #{q.enunciado}" style="color:black;" />
                    <br /> <br />
                    <p:outputLabel value="Resposta: #{q.resposta}" style="color:black;" />
                    <br />
                    <h:outputFormat
                        value="Sua Resposta: #{simuladoRealizadoBean.resposta('Parametro')}"
                        style="color:green;">
                        <f:param value="#{q.id}" name="id"></f:param>
                    </h:outputFormat>
                </div>
            </p:dataList>
        </h:form>
  • Is making a mistake?

  • JSF accuses Syntax error. and on the page launches Exception.javax.el.Methodnotfoundexception:

  • Puts your full bean class, has like?

  • I put Bean and XHTML.

  • it seems that he is not finding his method, use the whole name of it( getResposta)

  • The problem is that I’m trying to set and return with the GET method. How can I achieve an effect that looks like this and works? i need the output itself to pass the parameter to the bean and return the parameter.

  • Only with getResponse it works, but that’s not what I need, for each Datalist item it will set a value and then return something from that value. To be clearer, the 'Parameter' will be the question of dataList "q. id" from that id it will fetch in the MAP the answer that the user chose and return on the screen.

Show 2 more comments
No answers

Browser other questions tagged

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