• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2027
  • Last Modified:

How do I access a textfield value using JSTL?

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
JeraldFernando
Asked:
JeraldFernando
1 Solution
 
rrzCommented:
> - 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
 
JeraldFernandoAuthor Commented:
Patrially helped me in acheiving what I need
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now