1

I want to show a enabled or disabled button based on a value inside a foreach. It should check if the value is "true"- a string and display a button(html button) that looks enabled. If it's false it should look disabled.

<table border ="1">
        <tr class ="tableheading">
            <td>UniqueId</td><td>ClientId</td><td>Request Date and Time</td><td>Connection Status</td></tr>
    <c:forEach items="${list}" var="item">
    <tr  class ="rowstyle">
        <td  class ="rowstyle">${item.getUniqueId()}</td>
            <td >${item.getClientId()}</td>
            <td >${item.getRequestDateTime()}</td>
            <c:choose>
                <c:when test = "${item.getConnectionStatus == true}">
                    <td ><a href="screenviewer.html?clientID=${item.getClientId()}"><button style = "width:60px">${item.getConnectionStatus()}
                </c:when>
                <c:otherwise>
                    <td ><a href="screenviewer.html?clientID=${item.getClientId()}"><button disabled style = "width:60px">${item.getConnectionStatus()}
                </c:otherwise>
            </c:choose>-->

            </button></a></td>

       </tr>
    </c:forEach>
    </table>

The <td> with button should be displayed if getConnectionStatus is true.

Exception:

org.apache.jasper.JasperException: An exception occurred processing JSP page /DisplayClientLoginDetails.jsp at line 44

Line 44:

44: <c:when test = "${item.getConnectionStatus == true}">

Bean class:

public class ClientLoginBean {
private String UniqueId,ClientId,RequestDateTime,connectionStatus;

public String getUniqueId() {
    return UniqueId;
}

public void setUniqueId(String UniqueId) {
    this.UniqueId = UniqueId;
}

public String getClientId() {
    return ClientId;
}

public void setClientId(String ClientId) {
    this.ClientId = ClientId;
}

public String getRequestDateTime() {
    return RequestDateTime;
}

public void setRequestDateTime(String RequestDateTime) {
    this.RequestDateTime = RequestDateTime;
}

public String getConnectionStatus() {
    return connectionStatus;
}

public void setConnectionStatus(String ConnectionStatus) {
    this.connectionStatus = ConnectionStatus;
}

}

Abhi
  • 1,512
  • 2
  • 22
  • 46
  • You forgot to tell about the exception you got. Now you got a completely wrong answer as result of a shoot in the dark. A good exception already represents the whole answer at its own. We are capable of translating them in layman's terms so you finally understand them. Just include them in the question and don't ignore them as if they are decoration. – BalusC Mar 07 '16 at 12:56
  • @BalusC. I've edited the question to add the exception – Abhi Mar 07 '16 at 13:04
  • Great! It's however not exactly the exception itself. It's just an informal message. It clearly says "An exception occurred". It's not the exception itself. Now, please find that exception in server log. As said, it represents the whole answer at its own. – BalusC Mar 07 '16 at 13:09
  • @BalusC Hi..changing the name of `ConnectionStatus` variable in the bean class to `connectionStatus` and accessing it as ` ` like @Jax said worked instead of using the `getConnectionStatus()` although I dont understand why it worked. The exception was `el.PropertyNotFoundException` – Abhi Mar 08 '16 at 04:49
  • Exactly as I guessed. See duplicate for the answer and explanation on that. – BalusC Mar 08 '16 at 07:34
  • @BalusC But I have a `getConnectionStatus()` method ._. see my bean class..the working one. `getConnectionStatus()` didnt work when the variable name was `ConnectionStatus`. I read that if we access with variable name, it automatically lowercases the variable and adds `get` and looks for getter method. But I directly accessed the `getConnectionSTatus()` method – Abhi Mar 08 '16 at 09:29
  • You didn't access `getConnectionStatus()` method. You accessed `getConnectionStatus` property. This doesn't exist. – BalusC Mar 08 '16 at 10:05
  • @BalusC. oh..I think I missed the `()` – Abhi Mar 08 '16 at 10:16

1 Answers1

0

Without the full exception it is hard to know for sure, my guess would be your the getter in your test statement test = "${item.getConnectionStatus == true}". Here is a little snippet from some Oracle docs,

If value-a is a JavaBeans object, coerce value-b to String. If value-b is a readable property of value-a, then return the result of a get call. If the get method throws an exception, an error is returned.

Have you tried accessing the connectionStatus on your item by the implicit getter method of EL (remove get and change the property value to lower-case)?

<c:when test="${item.connectionStatus == true}">
Shaggy
  • 1,444
  • 1
  • 23
  • 34
  • Hi..changing the name of `ConnectionStatus` variable in the bean class to `connectionStatus` and accessing it as ` `like you said worked instead of using the `getConnectionStatus()` although I dont understand why it worked. – Abhi Mar 08 '16 at 04:48
  • I think you are unclear on how to access object properties in JSTL. Check out [this](http://strutscr.uw.hu/0066.html) and see if it helps. – Shaggy Mar 08 '16 at 13:19