File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Accessing controls? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Accessing controls?" Watch "Accessing controls?" New topic
Author

Accessing controls?

Mark Dragan
Greenhorn

Joined: Sep 28, 2010
Posts: 18
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

Joined: Apr 15, 2008
Posts: 198
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

Joined: Sep 28, 2010
Posts: 18
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

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing controls?