In the debugger I can see that the value of someBean.id is resolved after I trigger the link. Is it possible to force JSF to resolve the value immediately, so the bean that provides the id value is not required later?
I'm afraid not. The commandLink tag does not render as an HTML anchor tag ("a href="). Instead, it renders as a form postback directive.
In any event, external parameter passing isn't how JSF was designed to pass data. As a rule, you should properly have simply injected the "someBean.id" directly into the "bean" bean and not coded it on the View Definition at all.
If you really must use "f:param", try making "someBean" in View scope so that it will be removed once your commandLink action has navigated to the next View.
An IDE is no substitute for an Intelligent Developer.
Joined: Oct 07, 2011
Actually, I didn´t want to use external parameters. I just wanted to make a download link. My first try was:
SomeBean has a method public void download, which renders data to the HttpServletResponse. It works inside a primefaces data table, but it did not work inside a plain command link, the download method was never triggered. So I tried to create another request scoped bean "bean", which gets the object id from the parameters, retrieves the object and delegates the download request to it.
Yes, to use a view scoped beans would be possible, but I use spring and would have to implement a custom scope, and I just don´t like such workarounds. There should be more staight forward solution.
When you work with JSF, for all intents and purposes, you don't have an HttpServletResponse stream. JSF own the HttpServletResponse lock, stock, and barrel, and the only valid way to insert stuff into the HttpServletResponse outputstream is via a custom renderer so that JSF can insert it according to its own rules in its own time and in co-ordination with all of the other JSF components it is managing.
In particular, you should absolutely, positively never attempt to create anything whose Content-Type is not "text/html" via JSF. Especially PDFs or Microsoft Office documents.
JSF isn't the Master Control Program from Tron. It is a framework for presenting and processing HTML forms. If the output isn't an HTML form, use a servlet or (non-JSF) JSP, instead. JSF session objects and J2EE session objects are (once constructed) one and the same thing, so it's easy for Plain Old J2EE and JSF to co-exist in harmony and co-operation in the same webapp.
If you use a servlet to download (and possibly generate) a non-JSF document, you should have no problem building the necessary URL via the h:outputLink tag.
Joined: Oct 07, 2011
Ok, writing a servlet would probably be the simplest way.