更改托管bean的呈现属性 [英] change rendered attribute from managed bean
问题描述
我正在尝试使用JSF,情况如下:
Im am experimenting a bit with JSF, the scenario is the following:
我有一个会话范围的托管bean
I have a session scoped managed bean
@ManagedBean(name = "rand")
@SessionScoped
我已经声明了以下内容(除其他事项外):
where i have declared the following (among other things):
private UIOutput uiOutput;(plus getter and setter)
在我的facelets页面中,
In my facelets page i have
<h:outputLabel for="userGuess" binding="#{rand.uiOutput}"
value="#{rand.listSize}" rendered="false"/>
页面上有一个按钮,还有我所拥有的按钮的操作方法
there is a button on the page, and on the action method of the button among other things i have
this.uiOutput.setRendered(true);
但是它似乎不起作用,该元素将不会呈现.
But it does not seem to work, the element will not be rendered.
如果以渲染形式启动它并更改属性(将其设置为true或false),则它将起作用. 我怀疑这与以下事实有关:未渲染的元素未绑定到我在托管bean中拥有的uiOutput对象.在这种情况下如何使它工作?
If a start it as rendered and change the attribute (setting it true or false) it works. I suspect it has something to do with the fact that the element starting as not rendered is not bound to the uiOutput object i have in my managed bean. How can i make it work in this case?
推荐答案
我更改了一件事,现在可以正常工作了,我更改了按下按钮时运行的方法的返回类型,它返回了一个字符串值,导航到同一页面,它现在返回null,并且JSF不会生成新视图,而是呈现相同的视图,并且一切正常.
There is one thing i changed and now it is working, i changed the return type of the method i run when pressing the button, it returned a string value, navigating to the same page, it now returns null and JSF does not generate a new view , instead it renders the same view, and all is working.
我猜因为每次我将渲染值设置为true或false时都会渲染一个新视图,因为每次将组件设置为在新视图上渲染="false"都无关紧要.
I guess since a new view was rendered each time the fact that i set the render value true or false did not matter since each time the component was set to rendered="false" on the new view.
这篇关于更改托管bean的呈现属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!