2016-09-23 77 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