1

I would like to return the NOT of a Boolean function. As we know, we can do <... value="!something.field" ..>
But I would like to know how to return the not of a function like this <... value="!something.function(param)"...> The error is: "Cannot apply expression operators to method bindings" I tried also <... value="not .." ..> How can I do this ?

my code:

<h:outputText value="Inf"
              rendered="#{not managedBean.isEditableCell(buffer.bufferParam)}"/>

where buffer is a var for dataTable. I got error as described above.

Thanks.

Tiny
  • 27,221
  • 105
  • 339
  • 599
Saeed isa
  • 330
  • 3
  • 18
  • Show some code of your's – Sarz Oct 27 '14 at 08:01
  • @Sarz I dont have Code right now, I removed it. I will try to describe it more: when you use the render property render="#{manageBean.isTheValueTrue(someString)}" this is normal use, but what should I do if i want the opposite like render="#{NOT manageBean.isTheValueTrue(someString)}" without write another function returns the Not of the main function – Saeed isa Oct 27 '14 at 08:11
  • see this http://stackoverflow.com/questions/4870462/conditionally-displaying-jsf-components – Sarz Oct 27 '14 at 08:38

1 Answers1

1

If you use EL 2.2, You can send parameter as an argument to a method i.e. bean.actionMethod(Type param1, Type param2).

The example is shown below.

xhtml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>return the NOT of a boolean function</title>
    </h:head>

    <h:body>
        <h:form>
            <p:inputText value="#{inverseBean.inputVal}" 
                         rendered="#{inverseBean.isRender(15)}"/>
            <p:inputText value="#{inverseBean.inputVal}" 
                         rendered="#{not inverseBean.isRender(15)}"/>
        </h:form>
    </h:body>

</html>

managedbean

/**
 *
 * @author Wittakarn
 */
@ManagedBean(name = "inverseBean")
@ViewScoped
public class InverseBean implements Serializable {

    private String inputVal;

    public String getInputVal() {
        return inputVal;
    }

    public void setInputVal(String inputVal) {
        this.inputVal = inputVal;
    }

    public boolean isRender(int val) {
        boolean render;
        if (val > 5) 
            render = true;
        else
            render = false;

        inputVal = String.valueOf(val);

        return render;
    }
}
wittakarn
  • 3,124
  • 1
  • 18
  • 31
  • @Saeedisa It work for me. What EL version that you use? If it lower than 2.2 you cannot send parameter as an argument to a method. – wittakarn Oct 28 '14 at 16:52
  • @wittakarn It didn't work for me. How do you know which EL version primefaces use? I'm using primefaces 4.0. thanks – Doug LN Aug 22 '19 at 03:48
  • 1
    @DougLN EL version is not relate to primeface, it relate to Servlet that you used. Please see here https://stackoverflow.com/a/7237216/1242160 – wittakarn Aug 23 '19 at 14:47