简体   繁体   English

JSF在布尔标志上添加一个commandLink标记或outputText标记

[英]JSF add a commandLink tag or outputText tag depand on a boolean flag

I have a userBean object with name , id , boolean isConnected . 我有一个name idboolean isConnected userBean boolean isConnecteduserBean对象。

I built a login page using JSF. 我使用JSF构建了一个登录页面。 If one login successfully, the next page is a table of all users (name, id) 如果一次登录成功,则下一页是所有用户的表(名称,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. 我想要的是在登录其ID的用户列上将显示在h:commandlink ,其余用户ID将在h:outputText标记中。

When the user logged in his isConnected flag ( boolean ) is true and all other users are false . 当用户登录时,其isConnected标志( boolean )为true ,其他所有用户为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 . 类似于在我的managerBean上调用一个方法,该方法将根据页面init上的用户标志发送不同的字符串。

The simplest way is probably to use the rendered attribute of the outputText and commandLink tags. 最简单的方法可能是使用outputTextcommandLink标记的rendered属性。

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>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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