简体   繁体   中英

Conditional Order of JSF Elements

I have two JSF elements (eg, an input text, and an image). For some condition (eg, if a user is logged in), I want the input text to be rendered first. For the opposite condition (eg, the user is anonymous), I want the image to be rendered first. Is there a way to accomplish that (that can scale to more than just 2 elements)? The only idea I have, which looks hacky, is the following:

<h:inputText rendered=#{condition}/>
<h:graphicImage/>
<h:inputText rendered=#{!condition}/>

I would use CSS to solve this. Roughly it comes down to:

XHTML:

<div class="container input#{condition ? 'First' : 'Last'}">
    <h:inputText/>
    <h:graphicImage/>
</div>

CSS:

.container { overflow: auto; }
.container.inputFirst input { float: left; }
.container.inputLast input { float: right; }

Again, this is rough. It's just to give you an idea. Customize it to your needs. There are many ways in which you could style this.

If you want to use flex, try:

.container { display: flex; }
.container.inputLast { flex-direction: row-reverse; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM