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 Variable for a form value? 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 "Variable for a form value?" Watch "Variable for a form value?" New topic
Author

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:

display.jsp


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
Sheriff

Joined: Feb 05, 2003
Posts: 4727

KB,
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++ + ")" %>' />
</logic:iterate>

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
Greenhorn

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]}   
</c:forEach>
</c:when>

Please let me know if anybody has idea about this.

Thanks,
Archana.


SCJP,SCWCD,SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable for a form value?
 
Similar Threads
question for Struts 1.1 tld
Information lost on error.
using radio button in struts
Arraylist in JSP with Html radio
Html Radio buttons and Arraylist