【问题标题】:If-Else statement in with JSF [duplicate]JSF 中的 If-Else 语句 [重复]
【发布时间】:2017-02-01 09:34:44
【问题描述】:

我有一个网站,上面显示了一些列表。 现在,列表显示在两列中,即使只有 2 或 3 个列表元素(看起来很愚蠢),但我只想显示在一列中。

有什么方法可以用 > 和

这是我做的,但不起作用:

<ui:if value="#{graphicDynamic.elements.size < 3}" var="hotspots" >
     ...do the one column thing...
</ui:if>
<ui:else>
    ..do the other thing...
</ui:else>

【问题讨论】:

标签: jsf el


【解决方案1】:

有一个解决方案,也许它有时会对某人有所帮助......无论如何,这是我的解决方案:

<!-- Has more then 3 elements - display hotspots in two columns -->   
<h:outputLabel rendered="#{SomeClass.hasMoreThanThree}" >           
     Render the site elements for this case
</h:outputLabel>            

<!-- Has less then or 3 elements - display hotspots in one column -->
<h:outputLabel rendered="#{not SomeClass.hasMoreThanThree}" >           
     Render the site elements for this case
</h:outputLabel>

在控制器中:

public class SomeClass implements Serializable {

private boolean hasMoreThanThree; 

public SomeMethod(SomeType someParameter) {
    ...some code...
    setHasMoreThanThree(someList.size());
    ...some more code..
}

public boolean getHasMoreThanThree() {  
    return hasMoreThanThree;
}

public void setHasMoreThanThree(int size) {
    if (size >= 3){
    this.hasMoreThanThree=true;
    }
}   

【讨论】:

    【解决方案2】:

    以下不是更简单

    <!-- Has more then 3 elements - display hotspots in two columns -->   
    <h:outputLabel rendered="#{bean.value ge 3}" >           
         Render the site elements for this case
    </h:outputLabel>            
    
    <!-- Has less then or 3 elements - display hotspots in one column -->
    <h:outputLabel rendered="#{bean.value le 3}" >           
         Render the site elements for this case
    </h:outputLabel>
    

    【讨论】:

    • 会,但不会涵盖“size = 3”的情况。我试过了: 但是 ">=" 运算符不起作用,render-Exception 或类似的事情发生了......
    • 好的,简单的更改将 gt 更改为 ge for >=
    • 请注意,如果它的大小是 3,那么上面的两个标签都会被渲染。如果您不想在大小小于 3 的情况下呈现第二个输出标签,请使用 lt 而不是 le
    猜你喜欢
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2017-11-21
    • 1970-01-01
    • 2016-11-21
    • 2019-04-09
    相关资源
    最近更新 更多