开发者

How can I set a bean property when the page is loading in jsf?

In my project, I am using myfaces 1.2, rich faces 3.3.3 and spring 2.5 for backing beans. I searched over Internet for this simple need all weekend but I couldn't managed to set the bean property. h:inputhidden trick is good for calling a bean function. But I couldn't use this to set the property. For instance I want to set a bean property named as "number" to 开发者_JS百科"1" when a page is loading.

Over internet I saw these was being used to set the bean property. I am new in web programming and I don't know how these working.. But maybe these make you remember something.

HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
request.getParameter()
<h:inputhidden>

Updated: I want to set the value from the page not in bean. so I must get the value from the page. I will set the bean property differently in different pages. and I am using one bean for multiple page.


You can use:

  • <f:view before="#{bean.beforePhaseMethod}"> (if using facelets it's called beforePhase)
  • a @PostConstruct method for request-scoped beans
  • if there is no logic, simply give an initial value of the field private int foo = 1
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜