We help IT Professionals succeed at work.

what is ${status.value} and ${(branch.key)???

chaitu chaitu
on
Medium Priority
297 Views
Last Modified: 2010-04-01
i dont know JSTL much;what contents should i set in branches ?what is ${status.value}???


<c:forEach var='branch' items='${branches}'>
                <c:set var="chk" value="false"/>
            <c:forEach var='branch1' varStatus="stat" items='${status.value}'>
                  <c:if test="${(branch.key)==status.value[stat.index]}">       
                      <c:set var="chk" value="checked"/>
                  </c:if>
                </c:forEach>      
      <input type="checkbox" name="${status.expression}"
                              <c:out value="${chk}"/>
                              value="${branch.key}" />${branch.value}
                              <br/>
      </c:forEach>
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
branches is the name of the collection you want to iterate over in 1st loop
the inner loop will iterate over the value of the value property of the status bean ie. status.getValue()

Author

Commented:
show me an example so that I will understand better
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
branch.key is the is the value of the key property of the current element for the outer loop
ie.  branch.getKey()
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
example of what exactly?

Author

Commented:
branches.add("aaa");
branches.add("bbb");

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
jstl is primarily for accessing bean properties, not for making arbitrary method calls.
That should be handled in your controller.
ManishLead
CERTIFIED EXPERT

Commented:
objects,
   Any good JSTL tutorial or ref?

Author

Commented:
getting exception in jsp code....

            <c:forEach var='branch' items='${branches}'>
                <c:set var="chk" value="false"/>
            <c:forEach var='branch1' varStatus="stat" items='${status.value}'>
      <c:if test="${(branch.key)==status.value[stat.index]}">       
          <c:set var="chk" value="checked"/>
      </c:if>
          </c:forEach>      
      <input type="checkbox" name="${status.expression}"
                              <c:out value="${chk}"/>
                              <c:out value="${branch.key}" />${branch.value}
                              <br/>
      </c:forEach>

javax.servlet.ServletException: Unable to find a value for "key" in object of class "java.lang.String" using operator "."


controller
*********

      branches.add("1111");
            branches.add("2222");
            branches.add("3333");

String[] user=  (String[])branches.toArray(new String[0]);

        request.setAttribute("branches",branches);
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
branches is a list of strings, so branch will be a String

and here:

     <c:if test="${(branch.key)==status.value[stat.index]}">      

you try to access the key property of branch which does not exist
ie. String does not have a method getKey()

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.