2016-09-23 76 views
0

我有一個網站上顯示了一些列表。 現在,即使只有2或3個列表元素(看起來很愚蠢),列表顯示在兩列中,但我只想顯示在一列中。If-Else statement with JSF

有什麼辦法可以用>和<運算符添加if-else語句嗎?

這是我做的,但不工作:

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

這是類似的,但不是我問..已經檢查了 –

+0

見http://stackoverflow.com/questions/7145574/using-greater-than-logical-expression-in-rendered-attribute –

+0

也許試試呈現標記 –

回答

0

得到了一個解決方案,也許它可以幫助別人有時......不管怎麼說,這裏是我的解決方案:

<!-- 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; 
    } 
} 
0

豈不以下已經簡單

<!-- 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> 
+0

它會的,但「size = 3」的情況不會被覆蓋。我嘗試過: = 3}」> 但「> =」運算符沒有工作,渲染異常,或類似的情況發生... –

+0

好吧簡單改變'gt'爲'ge'> = – PDStat

+0

注意,如果它的大小是3,那麼上面的兩個標籤都會被渲染。如果您不想在尺寸小於3的情況下渲染第二個輸出標籤,則使用'lt'而不是'le' – PDStat