Saeed isa
Saeed isa

Reputation: 418

PrimeFaces: return the NOT of a boolean function

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.

Upvotes: 1

Views: 2489

Answers (1)

wittakarn
wittakarn

Reputation: 3162

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

Upvotes: 1

Related Questions