开发者

JSF Spring Bean set property

开发者 https://www.devze.com 2022-12-25 15:39 出处:网络
i have a JSF web application. I use 开发者_JS百科Beans as Spring Beans (not JSF managed beans). Now i have an URL to application www.example.com?parameter=2

i have a JSF web application. I use 开发者_JS百科Beans as Spring Beans (not JSF managed beans). Now i have an URL to application www.example.com?parameter=2

I would like to set this parameter into bean on the page load. I now how to do this with spring web flow but with JSF Navigation i cant do this.

What do you think about using JSTL c:set or jsp:setProperty?

Thanks for your help.

Kind regards Sebastian


From here:

One could extend a Springs org.springframework.beans.factory.config.PropertyPlaceholderConfigurer which accesses the RequestContext (org.springframework.web.context.request.RequestContextHolder#getRequestAttributes()) to resolve ${xyz}-like properties in the bean. Of course that would only work for Spring beans with “request”-scope.

If the bean is in session-scope you could simply use the following in a Phase Listener method:

property = FacesContezt.getCurrentInstance().getExternalContext
      .getRequestMap().get("paramName");

the phase listener is defined with

<f:view beforePhase="#{bean.method}">

if using facelets, its beforePhaseListener

If you were using faces-context.xml, you could've used the <managed-property>.

0

精彩评论

暂无评论...
验证码 换一张
取 消