Is it possible to "execute"/"render" various c:set
tags when a certain button is pressed and a redirect will occure?
I dont want to set the properties of the backing bean code-wise, for im filling them with static data. As im not talking about one single button here but about multiple ones, doing this code-wise would produce lots of boilerplated code. Thats the reason why I want to use c:set
.
The <c:set>
is the wrong tool for the job you had in mind and therefore insuitable. It doesn't run during submitting the form, but during building the view.
Use <f:setPropertyActionListener>
instead. E.g.
<h:commandButton value="Submit" action="#{bean.submit}">
<f:setPropertyActionListener target="#{bean.property1}" value="value1" />
<f:setPropertyActionListener target="#{bean.property2}" value="value2" />
</h:commandButton>
A completely different alternative is to just send request parameters by <f:param>
. This allows you creating bookmarkable links which is much better for user experience and SEO.