wood burning stoves 2.0*
The moose likes JSF and the fly likes how to render a component based on condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to render a component based on condition" Watch "how to render a component based on condition" New topic
Author

how to render a component based on condition

srikanth Thandra
Ranch Hand

Joined: Mar 04, 2009
Posts: 42

hi all,
I have a component say,<h:selectOneMenu> .To this i am binding values using <f:selectItems>. In the backing bean i am getting values from database into a map and i am binding that map to <f:selectItems> like as shown below:

<h:selectOneMenu>
<f:selectItems value="#{sessionScope.mapValue}"/>
</h:selectOneMenu>

Now my requirement is that when mapValue is in sessionScope then only <h:selectOneMenu> should render. How can we achieve this in jsf.



Someone throw some light on this. ..


Thanx in advance,
Srikanth
Rhys Emmerson
Greenhorn

Joined: Jul 23, 2010
Posts: 7
Hi, I think something like this might work.



Most other components will have a rendered attribute, it's strange that selectItems doesn't since it's just rendering <option> tags.
srikanth Thandra
Ranch Hand

Joined: Mar 04, 2009
Posts: 42

But when value binded to f:selectItems is null the page is not loading in the browser.

In my page i have a <h:selectOneMenu> coponent with <f:selectItems>. To this selecItems Iam binding a sessionScope map like

<f:selectItems value="#{sessionScope.valuesMap}"/>

If i write like below in my page
<h:selectOneMenu>
<f:selectItems value="#{sessionScope.valuesMap}"/>
</h:selectOneMenu>

In the browser i am getting error like selectItems found null. and the page is not displaying. How can we write the null checking condition on this so that the page can render normally.
Rhys Emmerson
Greenhorn

Joined: Jul 23, 2010
Posts: 7
srikanth Thandra wrote:
But when value binded to f:selectItems is null the page is not loading in the browser.

In my page i have a <h:selectOneMenu> coponent with <f:selectItems>. To this selecItems Iam binding a sessionScope map like

<f:selectItems value="#{sessionScope.valuesMap}"/>

If i write like below in my page
<h:selectOneMenu>
<f:selectItems value="#{sessionScope.valuesMap}"/>
</h:selectOneMenu>

In the browser i am getting error like selectItems found null. and the page is not displaying. How can we write the null checking condition on this so that the page can render normally.


That isn't what you asked. I tried this with JSF 2.0 and 1.2 and couldn't replicate the error, when selectitems gets null it just doesn't render. It's most likely an exception that is being propagated up to the selectItems component or it might be something like if a map key/value is null, either way the solution is in your Java code rather than the presentation code.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to render a component based on condition
 
Similar Threads
dynamically selecting value from SelectOneMenu
Error binding a h:selectOneMenu to a LinkedList
h:selectOneMenu problem with bean actions
Setting the default drop-down list value
f:ajax to update h:selectOneMenu