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 calledbeforePhase
)- a
@PostConstruct
method for request-scoped beans - if there is no logic, simply give an initial value of the field
private int foo = 1
精彩评论