This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes    Retrieving the dynamic field values in JSP  (struts) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "   Retrieving the dynamic field values in JSP  (struts)" Watch "   Retrieving the dynamic field values in JSP  (struts)" New topic
Author

Retrieving the dynamic field values in JSP (struts)

Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 136
Hi,

I have a requirement, based on the custId i am passing from a JSP, i will fetch the respective fieldNames, fieldType, etc. Which will vary based on the custId that is passed to the DB.

in the JSP, I am sending a List which does have the customer details for the selected custId which is passed to DB:-

<table>
<c:forEach items="${form.custList}" var="custVO">

<tr>
<td>

<label><cut value="${custVO.fieldName}"/></label> //which is custName for this ID 100, simiarly for cust ID 200 will be getting a diff field
<c:if test="${custVO.fieldName() eq ("TEXT")}">
<input type ="text" name ="<cut value="${custVO.fieldName}"/>"/>
</c:if>

</c:forEach>

</table>

This will display the fieldName which is retrieved for the custId 100 along with the fieldtype which is fetched from the DB. The same will happen for the custid 200, etc. Which is fine.

But when i enter the value for the fieldName and submit , how i can retrive these values in the Struts Action as the fields displayed in the JSP will vary based on the CustId. Here

<input type ="text" name ="<cut value="${custVO.fieldName}"/>"/>

Here I am passing the fieldName which i retrived from the DB and setting it as the "name" attribute for input type=text. Because the fieldName will be dynamic.
Now how can i get those values in the action, i am not sure whether i can use a form here as we cant judge the attributes. Hence thought of using the request.getParameter(), but what i will pass as a "name" in request.getParameter() as the fieldNames are dynamic?

request.getParameter("${fieldName}") how to pass the fieldname which is dynamic in the request.getParameter()?

I was also going through the indexed properties, but i am not getting the correct picture how to use this? Please shed some light on this.

thanks.
Divya gold
Greenhorn

Joined: Oct 15, 2012
Posts: 1
Hi,
I have the similar problem, but I am working on ajax and javascript.
Please suggest.

Rithanya Laxmi wrote:Hi,

I have a requirement, based on the custId i am passing from a JSP, i will fetch the respective fieldNames, fieldType, etc. Which will vary based on the custId that is passed to the DB.

in the JSP, I am sending a List which does have the customer details for the selected custId which is passed to DB:-

<table>
<c:forEach items="${form.custList}" var="custVO">

<tr>
<td>

<label><cut value="${custVO.fieldName}"/></label> //which is custName for this ID 100, simiarly for cust ID 200 will be getting a diff field
<c:if test="${custVO.fieldName() eq ("TEXT")}">
<input type ="text" name ="<cut value="${custVO.fieldName}"/>"/>
</c:if>

</c:forEach>

</table>

This will display the fieldName which is retrieved for the custId 100 along with the fieldtype which is fetched from the DB. The same will happen for the custid 200, etc. Which is fine.

But when i enter the value for the fieldName and submit , how i can retrive these values in the Struts Action as the fields displayed in the JSP will vary based on the CustId. Here

<input type ="text" name ="<cut value="${custVO.fieldName}"/>"/>

Here I am passing the fieldName which i retrived from the DB and setting it as the "name" attribute for input type=text. Because the fieldName will be dynamic.
Now how can i get those values in the action, i am not sure whether i can use a form here as we cant judge the attributes. Hence thought of using the request.getParameter(), but what i will pass as a "name" in request.getParameter() as the fieldNames are dynamic?

request.getParameter("${fieldName}") how to pass the fieldname which is dynamic in the request.getParameter()?

I was also going through the indexed properties, but i am not getting the correct picture how to use this? Please shed some light on this.

thanks.
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Laxmi,


when i enter the value for the fieldName and submit


i dont understand this line. but you can use the java script events,all the function based on event and set the value in the hidden form field which you can retrieve on the next jsp.
Hope this will work for you.

Regards
Jatan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving the dynamic field values in JSP (struts)
 
Similar Threads
How to use Break / exist statement here in foreach (JSTL)
Validation for the Indexed properties dynamic fields in struts (JSP)
Concatenating textfield names with ${status.index}
how to do Multiple checkbox binding in spring
dynamic text box value into database