Is it possible to hide a div
etc based on a condition (like you do in rendered attribute with EL) without having to wrap it in a <h:panelGrid ...>
etc with a rendered attribute? It ruins my layout. I just need it for the logic, not the layout.
Asked
Active
Viewed 2.3k times
10

Matt Handy
- 29,855
- 2
- 89
- 112

LuckyLuke
- 47,771
- 85
- 270
- 434
-
1I wonder who voted for close... – LuckyLuke Apr 17 '12 at 18:10
-
2Why not using `h:panelGroup`? It will be rendered as `` (under some conditions).– Matt Handy Apr 17 '12 at 18:57
-
1The close vote is just a close as duplicate. Click `close` link to see it yourself. – BalusC Apr 17 '12 at 19:49
2 Answers
17
first of all you should not wrap your elements with h:gridPanel
which results in html table
instead you should wrap with h:panelGroup
which results in span
in html code , you can also add layout="block"
to h:panelGroup
to make it rendered as div
second you dont not use jstl when hiding div
instead do something like this
<div style="display:#{(myBean.hideSomeDiv)?'none':'block'}">My Div Content</div>
or
<h:panelGroup styleClass="#{(myBean.hideSomeDiv)?'hide':''">My Span Content</h:panelGroup>
where in css file add this :
.hide {
display: none;
}
INMO you always better hide in JSF with rendered="#{myBean.renderCondition}"
Take a look at BalusC over here Conditionally displaying JSF components
3
You could just do this:
<div style="display:#{yourBean.property}"></div>
Where yourBean.property would return 'none' to hide the div

roel
- 2,005
- 3
- 26
- 41
-
I was looking at the JSTL `if` etc, is that not better? And how would I use that if it is? – LuckyLuke Apr 17 '12 at 16:02
-
Don't know if it is better. The best is to use rendered as Daniel stated here below – roel Apr 18 '12 at 07:39