Reputation: 909
I have a JSF backing bean that is Spring managed but I would like to be able to make use of the @ManagedProperty from JSF. The following does not work:
@Component
@Scope(Scopes.REQUEST)
public class MyRequestBean {
@ManagedProperty(value="#{param.bcIndex}")
private int bcIndex;
public int getBcIndex() {
return bcIndex;
}
public void setBcIndex(int bcIndex) {
this.bcIndex = bcIndex;
}
}
Suggestions?
Upvotes: 1
Views: 1376
Reputation: 11742
Actually it is quite simple. I know of three ways to do your injection:
Use Spring's @Value
annotation together with implicit El #{param}
object:
@Value("#{param.bcIndex}")
private int bcIndex;
Make use of ExternalContext#getRequestParameterMap
in a @PostConstruct
/ preRenderView
listener:
//@PostConstruct
public void init() {
bcIndex = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("bcIndex");
}
Make a binding in your view utilizing <f:viewParam>
:
<f:metadata>
<f:viewParam name="index" value="#{myRequestBean.bcIndex}" />
</f:metadata>
Upvotes: 2