Solved

How do I access a textfield value using JSTL?

Posted on 2011-03-09
2
1,574 Views
Last Modified: 2013-11-24
Hi,

I have a jsp page which has JSTL code in it. I have a list of checkboxes with naming goes as chkbox1, chkbox2, chkbox3....

So on select of chkbox a corresponding fields with naming convention textfield1, select1 values has to be inserted into an arraylist.

What I have done so far is creating the textfield1 using the attached code.

What I need to know is :
  - how can we get the value of the [textfield, select] using jstl tag?
  - how can we create a arraylist in jstl?
  - how can a jstl send the arraylist to the action/model?

I have also attached a image of what the form will look like... So when I select the checkbox... The corresponding Label1 value, The select box value and the text field value has to be selected.

can you please provide a solution for my problem.

Thanks in advance
<c:forEach var="i" begin="1" end="9" step="1" varStatus ="status">
<c:set var="tdAttribute" value="tdAttribute${i}"></c:set>
<c:out value="${tdAttribute}" /> 
<c:out value="${param.tdAttribute}" />
</c:forEach>

Open in new window

preview.jpg
0
Comment
Question by:JeraldFernando
2 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 35085207
> - how can we get the value of the [textfield, select] using jstl tag?
If the JSP with the JSTL tag receives a request with the request parameters in it then you can use
${param.yourTextfieldName}  
and
<c:forEach var="current" items="${paramValues.yourSelectName}" >
      ${current}
</c:forEach>
to display the data.  

> - how can we create a arraylist in jstl?
You can not create an ArrayList using JSTL. JSTL is used to display your data.
You could create one in a scriptlet.

> - how can a jstl send the arraylist to the action/model?  
It could set the ArrayList (or the String[] that is in param) into session-scope. Afterwards it would be available.    

It would easier to take things one step at a time. For example here is a JSP that demonstrates the displaying of multiple values from a select. It just send the request to its self. Please just copy and paste.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<form>
<select name="selectTest" multiple="multiple">
           <option value="one">one</option>
           <option value="two">two</option>
           <option value="three">three</option> 
           <option value="four">four</option> 
</select>
<input type="submit"/>
</form>
<c:forEach var="current" items="${paramValues.selectTest}" >
      ${current}
</c:forEach>
</body>
</html>

Open in new window














 
0
 

Author Closing Comment

by:JeraldFernando
ID: 35339129
Patrially helped me in acheiving what I need
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java JDK Download 7 78
Exception after setting jdbc session management 2 52
topping1 challenge 7 73
web services creation SOAP vs REST 5 21
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.

864 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now