Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to use Struts map backed forms, JSTL, EL?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man, I'm having a heck of a time trying to figure out how to use Struts's map backed action forms to create dynamic forms in combo with JSTL and EL.

To review, you are supposed to be able to create a Struts Action Form bean with a getter and setter for a Map which can store dynamic form elements. So if you have a jsp which can have 1 - 300 questions, let's say, the Map will hold the key/value pairing for each question dynamically.

Once you've set up your Action Form with getMapValue and setMapValue (or whatever you want to name the methods), you can use special syntax to get or set the Map as shown:

<html-el:text property="mapValue(myKeyValue)"/>

Here, "mapValue(.." will call the getMapValue method in the Action Form bean.

All the examples I've seen for this use jsp scriptlets to iterate through the Map. I want to do this without scriplets.

Here's is a snippet of my .jsp for displaying a table of questions based on user input:


<html-el:form action="processAppQuestions.do">
<table>
<c:forEach var="questionMap" items="${formBean.questionMap}">
<c:set var="mapkey" value="${questionMap.key}"/>
<tr>
<td><c ut value="${questionMap.key}"/></td>
<td><c ut value="${questionMap.value.questionText}"/></td>

<td>
<!--Here's the culprit....-->
<html-el:text property="mapValue(${mapkey})" value=""/>
</td>
</tr>
</c:forEach>
</table>
<html-el:submit/>
</html-el:form>

Basically, my question is, can I use the special Struts map backed syntax in combo with EL as shown here?:

<html-el:text property="mapValue(${mapkey})" value=""/>

I'm doing something wrong because the name of the html text field is just using the string literal: "mapValue(1234)" . Everything, including all of the EL expressions is working fine, except the "mapValue" call is not executing. This is supposed to be calling the "getMapValue" method in my Struts ActionForm bean.

Any ideas?

GG
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic