0

in a JSF page I need to render a warning message to the user when the upload file is too big.

I already have the file size from the backing bean and want to compare this to a fixed number (1000) , but it doesn't seem to work.

 <h:outputText rendered="#{file.lines} > 1000" value="Too Big!"/>

The backing bean provides the correct file size, as I'm already displaying that:

 <h:outputText value="#{file.lines} lines" />

This works as expected, displaying the correct numbers of lines. Is it because the number returned from the bean is actually a String?

user3211098
  • 51
  • 1
  • 10
  • and what does `` show? true or false? I'm sure you've tried that – Kukeltje Jul 23 '19 at 11:56
  • No I did not try that, as I'm sure it will just literally write out the equation . - and yes, just to proof myself right, I did it and that's confirmed. – user3211098 Jul 23 '19 at 14:43
  • This question still has no answer. Is there anyone who has come across this before and found a solution? – user3211098 Aug 01 '19 at 08:34
  • Why should it output the equation instead of 'true' or 'false'? – Kukeltje Aug 01 '19 at 08:44
  • It is marked as duplicate, but how do I find the original? I did a search before posing this question and found nothing. I often see 'marked as duplicate' on questions, but never see a link to the 'original'. – user3211098 Aug 14 '19 at 10:14
  • The link is at the top of the question, just below the header, it always is... In a yellow box – Kukeltje Aug 14 '19 at 10:38
  • 1
    @Kukeltje: I completely agree this age-old UX fail though. I've told Stack Overflow about this and even spent more than 5000 meta-reputation bounty on [this](https://meta.stackexchange.com/q/239097/) during years but no one seems to understand. – BalusC Aug 15 '19 at 09:46

2 Answers2

1

The problem is, that the rendered-Attribute expects a boolean value - true or false. So if you write:

<h:outputText rendered="#{file.lines gt 1000}" value="Too Big!"/>

things should work. Here is an example with a simple bean:

package de.test;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
import lombok.Data;

@ManagedBean
@ViewScoped
@Data
public class SimpleTests implements Serializable {
    /** default sertial version uid.  */
    private static final long serialVersionUID = 1L;
    /** dummy for the number of lines. */
    private int lines = 27;
    /** dummy listener. */
    public void actionListener(AjaxBehaviorEvent event) {
         // dummy listener
    }   
}

and a simple page:

<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>Common check the lines</title>
</h:head>
<h:body>
    <h1>EL expressions</h1>
    <h:form id="testform">
        <h:outputLabel for="lines" value="Number of lines: "/>
        <h:inputText id="lines" value="#{simpleTests.lines}">
            <f:convertNumber integerOnly="true"/>
        </h:inputText>
        <h:commandButton type="button" id="btn" value="Common check the lines!">
            <f:ajax listener="#{simpleTests.actionListener}"
                    execute="@form"
                    render="@all"/>
        </h:commandButton>
        <br/>
        <h:panelGroup id="warning">
            <h:outputText value="Too Big!"
                style="color: red; font-weight: bold;"
                rendered="#{simpleTests.lines gt 100}"/>
        </h:panelGroup>
        <h:messages />
    </h:form>
</h:body>
</html>
jemie
  • 11
  • 2
1

The correct el syntax is rendered="#{simpleTests.lines gt 1000}" (gt for greater than and lt for less than)

Mike Balthasar
  • 173
  • 1
  • 7
  • Thanks, that worked. I had made two errors: using '>' rather than 'gt' and not enclosing it in inside the #{ }. – user3211098 Aug 14 '19 at 10:11