Results 1 to 6 of 6
  1. #1
    wonderpets is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default JSTL forEach Query

    Hi All,

    This is my first post to this forum so please let me know if I go off track.
    Can someone help me with a jstl forEach issue I have. We have been provided with jsp pages from an external company that we now have to incorporate our variable data. This is received in the normal way via collections. The problem I have is that the pages are structured with a series of divs specifying column 1 followed by a series of divs specifying column 2 etc... Each item from the collection, however, corresponds to a row across each of these divs.

    My first thought was to create variable fields from the collection so I could just place them into the right pages as below:

    <c:set var="count" value="1" />
    <c:forEach var="bookListEntry" items="${bookSearchResultList}" begin="${param.first}" end="${param.first + noOfRows - 1}">
    <c:set var="who${count}" value="${bookListEntry.artistName}"/>
    <c:set var="where${count}" value="${bookListEntry.countyName}"/>
    <c:set var="cost${count}" value="${bookListEntry.costRangeFrom}"/>
    <c:set var="bandIndex${count}" value="${bookListEntry.bandIndex}"/>
    <c:set var="proFile${count}" value="${bookListEntry.proFile}"/>

    <c:set var="count" value="${count+1}"/>
    </c:forEach>

    but according to the DTD atrribute var does not accept expressions. I'm using the begin and end attributes because I only want to partially traverse the collaction as there is a "next" and "prev" button at the bottom.

    My question is, is there any way to create a variable "var" name or alternatively can anyone think of a better way to do this.

    I hope this makes sense as it's always difficult to try and put into words something you've been working on for a while.

    Thanks for any help.

    Gareth

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default yep, it's them words again.

    What DTD, where?

    Last time I heard JSTL was not ready for PrimeTime. Did Marty get Vol-2 on the trucks yet?

    It does not take me a long time to figure this stuff, if you can give me a base reference page I may be able to provide some help. Your words are clear: get a var ( variable / label / whatever ) such that the expressions who / where / band / costIndex and proFile become ( words again ) assigned to a label in your source code such that they may be worked as any other variable in traditional code.

    Swamped right now with a major project, hope I helped you with your wording. Nil illegitimo in desperandum carborundum.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    wonderpets is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default JSTL forEach Query

    Thanks for the reply Nickolas and I appreciate your time (fully understand that you deadlines to meet). Hopefully, I can clarify what I said.

    When I said DTD a bit of dyslexia crept in. I meant TLD, sorry.

    I have put the jsp up as a text page so, hopefully, you can see what I mean instead of trying to decipher my babble. There is some hard-coding at the moment with c:set's but please ignore these for now.

    msgnitsolutions com test TestResults.txt

    Hopefully this makes a bit more sense.

    Thanks,

    Gareth

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default xml

    TLD's are in xml - you have to write the tags.

    who / where / cost / bandIndex / proFile should be in a Bean.

    Where is bookSearchResultList?

    As for time, I really put up some sloppy code in front of a convert from Captain Hoppers legendary business oriented language. That poster is a Navigator, but not a Browser.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  5. #5
    wonderpets is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default JSTL forEach Query

    Hi Nicholas,

    Thanks for the reply again. Unfortunately I'm under contract with my wife and I'm not allowed to work Saturday nights so I've only just got your reply.

    The properties you mentioned are defined in a bean bookSearchResultList which is built using a struts config file and appropriate servlet. When I hard-code this list of c:set's to use who1, where1 etc... everything works fine. The bean is picked up and everything is displayed correctly. It's only when I try to make the var property contain a variable name I am having problems.

    Is that COBOL you're talking about? I've not had the misfortune to use that for some years.

    Thanks again,

    Gareth

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Talking busy too

    Quote Originally Posted by wonderpets View Post
    Hi Nicholas,
    Hi, Gaeth.
    Quote Originally Posted by wonderpets View Post
    Thanks for the reply again. Unfortunately I'm under contract with my wife and I'm not allowed to work Saturday nights so I've only just got your reply.
    I have responses, we do not have a Wombat patch so I cannot do anything but let the moderators have a swipe at your swipe. ( weak humor, weak reference )
    Quote Originally Posted by wonderpets View Post
    The properties you mentioned are defined in a bean bookSearchResultList which is built using a struts config file
    Do you have some code snippets you can show me? I do not at this point even know what a c:set is.
    Quote Originally Posted by wonderpets View Post
    When I hard-code this list of c:set's to use who1, where1 etc... everything works fine. The bean is picked up and everything is displayed correctly. It's only when I try to make the var property contain a variable name I am having problems.
    Struts is an intermediary of some kind, I have no experience with struts.
    Quote Originally Posted by wonderpets View Post
    Is that COBOL you're talking about? I've not had the misfortune to use that for some years.
    Norm, this one's yours.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. How to use Foreach on an Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:06 PM
  2. Question regarding foreach loop...
    By theonlywalks in forum New To Java
    Replies: 2
    Last Post: 03-15-2008, 06:15 AM
  3. foreach in jstl to display nested colums-struts jsp
    By adil7 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-11-2008, 06:19 AM
  4. Jstl Exception Handling
    By vamsidharpoosarla in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-18-2007, 06:17 AM
  5. JSTL error
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-11-2007, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •