The moose likes Struts and the fly likes Variable for a form value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Variable for a form value?" Watch "Variable for a form value?" New topic

Variable for a form value?

Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
Howdy all.

On my jsp page, I'm displaying a list of options from a database:


However, the value assigned to each radio button is literally the String "<% custOrderBean.getDate().get(i);%>".

Is there anyway for me to assign the String value of custOrderBean.getDate().get(i) into the radio buttons value?
Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
Alright, I think I've solved it by using the following:

It's not quite what I wanted, but it should suffice.
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

You had another question which mysteriously disappeared as I replied to it.

It had to do with phone entries and I assume you're using Struts.

My reply:
It is very possible. It'll be kind of tricky and you'll probably need to use a "map-backed" form. I put map-backed in quotes because I think you're better off using an ArrayList.

Here is an example:

<% int count = 0; %>
<logic:iterate id="idNotUsed" collection='<%= getMyListSomehow() %>'>
<html:text property='<%= "value(name" + count++ + ")" %>' />
<html:text property='<%= "value(addr" + count++ + ")" %>' />
<html:text property='<%= "value(phon" + count++ + ")" %>' />

public void setValue(String key, Object value){
int count = Integer.parseInt(key.substring(4, key.length()-1));
String key = key.substring(0,4);
public Object getValue(String key){
int count = Integer.parseInt(key.substring(4, key.length()-1));
String key = key.substring(0,4);
return myList.getIndex(

A good workman is known by his tools.
Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
Thanks, I deleted the question because I had read elsewhere that Struts wasn't designed to handle what I was asking for (a JSP script with the ability to create Forms) as all Forms are created when then JSP first loads.
Archana Marathe

Joined: Jun 01, 2004
Posts: 3
Hi Mark,

I read the post by you regarding map backed forms. I am using map backed forms to generate a search criteria page dynamically. I could have <html:radio .. > as one of the elements on the JSP.

My problem is regarding prepopulation of the JSP page fields which uses map backed form. Is it possible to prepopulate th JSP when that JSP is genetated using map-backed forms?

Here is the code snippet I am using..

<c:when test="${queryForms.displayType == 'RadioButton'}">
<c:set var="displayTypeName" value="${queryForms.displayTypeName}"/>
<c:set var="displayValue" value="${queryForms.displayValue}"/>
<c:set var="delim" value=";"/>
<c:set var="buttonNameArray" value="${fn:split(displayTypeName, delim)}"/>
<c:set var="buttonValueArray" value="${fn:split(displayValue, delim)}"/>
<c:forEach begin="0" end="${fn:length(buttonNameArray) - 1}" var="token">
<html:radio property="param(${queryForms.paramName})" value="${buttonValueArray[token]}"/>${buttonNameArray[token]}   

Please let me know if anybody has idea about this.


I agree. Here's the link:
subject: Variable for a form value?
It's not a secret anymore!