Solved

How do I access a textfield value using JSTL?

Posted on 2011-03-09
2
1,630 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
strCount chalenge 3 87
mockito example issue 8 82
ejb entity bean example issue 2 16
how to debug htl and js pages 8 38
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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

840 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