Null parameters in JSF request

Asked

Viewed 359 times

2

I’m trying to send a parameter to a Spring bean but I’m not getting it, the map is always empty. Below is my code:

XHTML:

<h:dataTable columns="2" 
    value="#{tipoMaquinaView.objectSelecionado.imagens}" var="anexoImg" >
    <p:column>
        <p:graphicImage value="#{downloadUploadAnexo.image}"  cache="FALSE">
            <f:param name="anexo_id" value="#{anexoImg.id}" />
        </p:graphicImage>
    </p:column>
</h:dataTable>

Bean:

@Service
@RequestScoped
public class DownloadUploadAnexo implements Serializable {

@Autowired
private S3AnexoFacade s3AnexoFacade;

public StreamedContent getImage() {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        return new DefaultStreamedContent();
    } else {
        // Map abaixo sempre vazio
        Map<String, String> parameterMap = (Map<String, String>) context.getExternalContext().getRequestParameterMap();

        String anexoID = parameterMap.get("anexo_id");

        if (anexoID == null) {
            return new DefaultStreamedContent();
        }

        AnexoFacade anexoFacade = AppContext.getBean(AnexoFacade.class);    
        Anexo anexo = anexoFacade.buscarPorId(Long.valueOf(anexoID));

        InputStream stream = s3AnexoFacade.carregarArquivo(anexo.getCaminho());
        StreamedContent file = new DefaultStreamedContent(stream, anexo.getContentType(), anexo.getNome());     
        return file;
    }
}
  • Can you verify whether #{anexoImg.id} is not empty (e.g., printing in a column)?

  • Yes, it is not null, the value is "1".

  • Okay, you don’t have any redirects or anything like that in your mapping, right? You can increase the scope to session to test?

  • Another thing, try putting something fixed to see if it reaches the other side <f:param name="anexo_id" value="2" />

  • Then, the value does not arrive on the other side, fixed or parsed in the expression, the "parameterMap" is always empty, as if no parameter was passing. The situation was the same by changing the scope to "Session" and "Application".

  • One thing is that I am using webflow in my application... This may influence?

  • Yes, Daniel. I recommend the following; prepare one mvce (starting from scratch). 99% chance that you will find the step that is boring everything, if you do not find at least we will have an example to work.

Show 2 more comments
No answers

Browser other questions tagged

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