?
Solved

Modifying JSTL - incrementing a loop

Posted on 2005-03-23
8
Medium Priority
?
4,579 Views
Last Modified: 2013-11-24
hi!

I was wondering there is any way of increment the indicated line upon user's clicking button event...
So, redirect this page, but for each redirecting I want to increment the loop so this will make indentical table each time.

thanks,
+++++++++++++++++++++++++++
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<head>
<title>Example of a Bean Based Purchase Order</title>
</head>
<h1>Example of a Bean Based Purchase Order</h1>
<html:form action="/generateBeanPO">
<TABLE WIDTH="80%" BORDER="1">
<TR><TH align="left">Part Number</TH>
<TH align="left">Quantity</TH>
<TH align="left">Price</TH></TR>
<c:forEach var="lines" items="${purchaseOrderBeanForm.map.lines}" >---------------------------------!!!!!
  <TR><TD><html:text indexed="true" name="lines" property="partNumber"/></TD>
  <TD><html:text indexed="true" name="lines" property="quantity"/></TD>
  <TD><html:text indexed="true" name="lines" property="price"/></TD></TR>
</c:forEach>
</table>
<html:submit/>
</html:form>
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13620042
>> So, redirect this page, but for each redirecting I want to increment the loop so this will make indentical table each time.

I don't understand this bit :-(

Can't you just add one to the "purchaseOrderBeanForm.map.lines" collection when the form is posted?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13620666
If you want to use/access an incrementor in the JSTL forEach loop, you can use the "varStatus" object

e.g.

  <c:forEach begin="1" end="5" varStatus="count">
    <c:out value="${count.count}"/>: one row here...<br>
  </c:forEach>      

Prints out
---------------
1: one row here...
2: one row here...
3: one row here...
4: one row here...
5: one row here...

You might also want to look at the other properties of the varStatus object, including: index, current, first, last, begin, end and step. It can add a lot of extra power to a simple for loop.

As to the rest of the question, I'm not sure I understand either... sorry.
0
 

Author Comment

by:dkim18
ID: 13632460
Sorry for not making my explanation clear.
Here is the full story.

I need to make identical table upon user’s button click event. For example there is visit page with some text boxes and drop down menu boxes and if a user click “add new visit” then same table should appear under existing table. I am trying to use DynaActionForm and indexed properties and Beans as properties, but having hard time to figure this thing out.
I got the above code from one article on the internet and the corresponding struts-config.xml is this:
+++++++
struts-config.xml version 2
<struts-config>
 <form-beans>
   <form-bean name="purchaseOrderBeanForm" type="org.apache.struts.action.DynaActionForm">
     <form-property name="lines" type="article2.POLine[]" size="4" />   </form-bean>
  </form-beans>
 <action-mappings>
  <action path="/generateBeanPOForm" forward="/purchaseOrderBean.jsp"
          name="purchaseOrderBeanForm" scope="request"/>
  <action path="/generateBeanPO" type="article2.GenerateBeanPO"
          name="purchaseOrderBeanForm" scope="request" input="/purchaseOrderBean.jsp">
      <forward name="success" path="/displayPurchaseOrderBean.jsp" redirect="false"/>
  </action>
 </action-mappings>
 <message-resources parameter="ApplicationResources"/>
</struts-config>

+++++++++
The thing is how I change this whole thing dynamically, so it reacts user’s event(clicking button). I appreciate any comments or related articles or help.
0
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 

Author Comment

by:dkim18
ID: 13633715
Is it possible to dynamically increment variable "end" and reload page when a user click a "add visit" button? If so, struts-config will automatically change to indexed properties?

  <c:forEach begin="1" end="5" varStatus="count">
    <c:out value="${count.count}"/>: one row here...<br>
  </c:forEach>    
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 500 total points
ID: 13642920
>>Is it possible to dynamically increment variable "end" and reload page when a user click a "add visit" button? If so, struts-config will automatically change to indexed properties?

Yes. You can use JSTL to output our struts action form. Here's an example of an actionform in the request scope with a dynamic end variable

  <c:forEach begin="1" end="${dynamicEnd}" varStatus="count">
      <c:out value="${requestScope.ActionForm.poperty[count.count]}"/><br>
  </c:forEach>    
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 14385563
I'm happy with this
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question