Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing controls?

 
Mark Dragan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, I have question regarding how to access control from manged bean.While I was working in Asp.Net, when user clicked on some button I would show him another control, so my question is how I can from managed bean acess to specific control and adjust it's css so it would have attribute hidden or visible, for example if user click on button1 I want to show him button2.
Thanks in advance
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not saying if you are using JSF 1 or JSF 2. But I think the following is possible in both (at least with 2). Additionally you are not saying if you want the change happen immediately or after page reload. But you are saying that you want the access to be possible from the backing bean so here is one way to do that.

In addition to binding html element values to backing beans (with value="#{backingBean.elementValue}" you can also bind the entire html element to backing bean.and

I do not how usable this is but after reading many JSF 2 books I know that this is possible to do You can judge yourself if this is what you want
 
Mark Dragan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilari,
thank you very much for your quick reply, I'm using JSF 2.0 and this is exactyly what I needed.
Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In actuality, it's often more straightforward to simple have the hidden control include the boolean "rendered=" attribute and control its visibility from a backing bean. The master control can then fire an action processer that sets/resets the property references in the "rendered=" attribute.

Because we're talking HTTP here, firing an action will by default re-render the entire webpage, which is usually visually annoying. Fortunately, we live in modern times and can use AJAX to do partial page rendering. That's a standard feature under JSF2 and is possible under JSF1 using one of the AJAX-supportive extension tagsets. For example, RichFaces has a "reRender=" attribute that can be used to restrict the re-rendering to just the dependent control. You'll probably also want 'immediate="true"' on the master control.

Binding requires that you write JSF-specific Java code. Using the above technique works on ordinary POJO backing beans and doesn't lock them into the JSF framework. Plus, I think it's easier to understand.

Binding is useful and even essential in certain cases, but people over-use it. I think that may be partly due to out-of-date JSF documentation that didn't have more civilized techniques to call upon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic