0

I have a website on which are some lists displayed. Now, the lists are displayed in two columns, even if there are just 2 or 3 list elements (looks stupid), but I want be displayed in only one column.

Is there any way to add a if-else statement with > and < operators?

This is what I did, but doesn't work:

<ui:if value="#{graphicDynamic.elements.size < 3}" var="hotspots" >
     ...do the one column thing...
</ui:if>
<ui:else>
    ..do the other thing...
</ui:else>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Lazar Zoltan
  • 135
  • 3
  • 14

2 Answers2

1

Wouldn't the following have been simpler

<!-- 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>
PDStat
  • 5,513
  • 10
  • 51
  • 86
  • It would, but the case "size = 3" would not been covered. I tried: but the ">=" operator didn't work, render-Exception, or something like that happend... – Lazar Zoltan Oct 10 '16 at 14:01
  • Ok simple change changed `gt` to `ge` for >= – PDStat Oct 10 '16 at 14:21
  • Note obviously if it size is 3 then both the above labels would be rendered. If you didn't want to render the second output label for cases where size is less than 3 then use `lt` instead of `le` – PDStat Oct 10 '16 at 14:30
0

Got a solution, maybe it helps someone sometimes... Anyways, here is my solution:

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

In the Controller:

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;
    }
}   
Lazar Zoltan
  • 135
  • 3
  • 14