简体   繁体   中英

JSF add a commandLink tag or outputText tag depand on a boolean flag

I have a userBean object with name , id , boolean isConnected .

I built a login page using JSF. If one login successfully, the next page is a table of all users (name, id)

What I want is on the column of the user who logged in his id will be shown in a h:commandlink , and the rest of the users id will be in an h:outputText tag.

When the user logged in his isConnected flag ( boolean ) is true and all other users are false .

Is there a way to insert a different tag depand on a certain flag like mine? Something like call a method on my managerBean that will send a different string depending on the user flag on the page init .

The simplest way is probably to use the rendered attribute of the outputText and commandLink tags.

For example, something like the following:

...
<h:dataTable value="#{myBean.users}" var="user">
    ...
    <h:column>
        <h:commandLink rendered=#{user.connected} value="#{user.id}"/>
        <h:outputText rendered=#{!user.connected} value="#{user.id}"/>
    </h:column>
    ...
</h:dataTable>
...

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