0

EDIT: I flagged my question as a duplicate, because I've found the answer here: JSTL c:if doesn't work inside a JSF h:dataTable

I marked it as a duplicate instead of deleting it because I thought it could still help someone.

I suppose I'm making some stupid mistake, but the code inside <c:if> executes although the expression in test should evaluate to false.

Note: I know that when using jstl there should be ${...} instead of #{...} but I've tried that way too and there seems to be no difference.

<c:if test="#{(auction.isActive==0)}">
    <h:column>
        <f:facet name="header">Auction Number</f:facet>
            #{(auction.isActive)} //PRINTS 1
    </h:column>
</c:if>

What am I doing wrong? I'm using JSF - the code is for a .xhtml page.

My includes:

    <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:df="http://java.sun.com/jsf/composite/dreamcar_functions"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">

Sorry if this seems basic but I'm making my first steps with java-ee.

Edit - The getter and setter for isActive:

public int getIsActive() {
    return isActive;
}
public void setIsActive(int isActive) {
    this.isActive = isActive;
}

Check out this test I made. I changed auction.isActive==0 to auction.isActive to generate an error that would tell me details about auction.isActive. It seems the value here is 0:

/add_offer.xhtml @29,39 test="#{auction.isActive}" /add_offer.xhtml @29,39 test="#{auction.isActive}": Cannot convert 0 of type class java.lang.Integer to class java.lang.Boolean
Hello Lili
  • 1,527
  • 1
  • 25
  • 50
  • Several things... you mix namespaces from pre jsf-2.2 and jsf 2.2, correct that. Secondly, What does printing `#{(auction.isActive)}` (without the ==0) and outside the `c:if` show? And what is the method actually called? Please create a [mcve] – Kukeltje Dec 28 '17 at 19:03
  • @Kukeltje it prints 1 – Hello Lili Dec 28 '17 at 19:07
  • @Kukeltje isActive is a property (an int which is either 0 or 1), it's not a method – Hello Lili Dec 28 '17 at 19:09
  • @Kukeltje I've corrected the namespaces. No change though. – Hello Lili Dec 28 '17 at 19:11
  • There is a getter for it right? So there is a method. But if it actually prints 1 it looks there does not seem to be a problem in that area – Kukeltje Dec 28 '17 at 19:12
  • You corrected it the wrong way... If the jsf-2.2 namespace 'worked' then your **are** using js-2.2 and not using the jsf-2.2 namespaces can make a difference... try using the jsf-2-2 ones for all. – Kukeltje Dec 28 '17 at 19:17
  • @Kukeltje check out what the error tells me (added an edit to my question). It seems that the value of auction.isActive is 0 in that case. But why does the expression below the condition print 1? – Hello Lili Dec 28 '17 at 19:39
  • I never said to use the expression like that, the error is right... – Kukeltje Dec 28 '17 at 19:41
  • I used it like that to print some details. It says Cannot convert 0 of type class java.lang.Integer to class java.lang.Boolean - note, 0, which means (at least to me) - that in that part of the code, auction.isActive evaluates to zero, not one. – Hello Lili Dec 28 '17 at 19:43
  • In the first comment I made, there was something about [mcve]. Please create one... Too much trial and error here now... – Kukeltje Dec 28 '17 at 19:49
  • @Kukeltje I found the answer, this question is a duplicate. Should I delete it, or do you think it can help anybody? – Hello Lili Dec 28 '17 at 20:32

0 Answers0