Solved

How do I access a textfield value using JSTL?

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

708 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

11 Experts available now in Live!

Get 1:1 Help Now