How can I pass a parameter to a method and at the same time return the value of the method 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 from 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 has a syntax error. and the page throws exception.javax.el.MethodNotFoundException:
Full Bean.
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>