Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

processing dynamic field name?  RSS feed

 
Philip Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
howdy y'all.

My problem.

In FORM i have :

<td><input name="${dynamic.name}" type="checkbox">

and I am trying to see on the form action which has been checked with:

<c:if test="${param.${dynamic.name}} == ${dynamic.name}">

but it's not having it, I've been doing this in PHP.

Can anyone please point this long gone lonsome cowboy the way back home.

Phil
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to grab a copy of the JSP Specification (see JSP FAQ) and bone up on EL operators and notation. The ${} is not an EL 'fetch' operator, but are delimiters that surround the complete EL expression. As such, using 3 such delimiters in a single expression makes no sense.

The general dereferencing operation in the EL uses the square brackets, with the period character available for use in some circumstances.

Therefore (if I am correct in what you are trying to achieve), your test would be more along the lines of:

 
Philip Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Bear,

tahnks for your reply, unfortunatley I don't have exact code in front of me so I will try to explain as best as I can.

Rough Idea of code:

From form:
-----------------
<sql query var="exQuery">
...
...
<c:forEach var="dymanic" items="exQueryRows">
<input type="checkbox" name="${dynamic.id}"
<submit>

+++ ie, check box names are created dynamically ++++

--------------
in action jsp
--------------
<sql query var="exQuery">

...
...
<c:forEach var="dymanic" items="exQueryRows">
<c:if param.${dynamic.id} == {dynamic.id}>

in short, I want my sql result to be able to auto complete my param."blank" field name


so i can roll through database results and see if any equal to database result. if the do it means it has been checked.

in php parlance it is something like

if (POST_[dynamic.id]) or something or rather...



much appreciated, pardner.
 
Philip Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
has no body come acrtoss this before?

please if canybody can help, do.

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can tell, my previous response answers your question.
[ March 21, 2006: Message edited by: Bear Bibeault ]
 
Philip Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Unfortunatley this does not answer my question. I have tried your code

${param[dynamic.name]}

<c:if test="${param[dynamic.name]}">
<c ut value="abc_${param[dynamic.name]_cba} />


and it outputs "abc__cba" ie. nothing.

I do hope you can show me where I am wrong. I hope someone can help.

If I am not mistaken this "is" where a java greenhorn can get some "help"

kind regards

Phil
 
seemapanth Joshi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason you can't use scripting in here.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seemapanth Joshi:
Any reason you can't use scripting in here.


Because he's using JSP 2.0 where scripting is a discouraged practice.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Philip Brown:

<cut value="abc_${param[dynamic.name]_cba} />

and it outputs "abc__cba" ie. nothing.


What is the value of dynamic.name at this point? If it's not what you expect, you can back-track to find out why.

If it is what you expect, is there really a request parameter of that name submitted?

The syntax is correct, it's the scoped variables and environment that probably need debugging at this point.
[ March 22, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. If you click the 'disable smilies' checkbox when posting code, your <c:out> tags will look a lot less surprised.
[ March 22, 2006: Message edited by: Bear Bibeault ]
 
Philip Brown
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks for keeping this post alive. it seems as there is some interest...

I am posting my two jsp pages I am working with, which follows:

it seems what I am trying to do is not possible in JSP otherwise I would have had a quick working example back, however it seems, common enough to have some solution and I am determined to find it for myself and all who follow.

please help look throgh code and help if possible

kind regards,

Philip
p.s. right at bottom is how I have done it in php previously.

makenewsletter.jsp+++++++++++++++++++++++++++++++++++++++++++++++++++

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="sql" uri="/jstl/sql" %>
<%@ taglib prefix="c" uri="/jstl/c" %>
<sql:query var="newsQueryResults" dataSource="jdbc/mysqldb" >select * from newsroom order by newsDate DESC limit 20</sql:query>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<form action="viewnewsletter.jsp" method="post" name="addnews">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><span class="style4">NEWSLETTER DATE </span></td>
<td><input type="text" name="date" width="250"><span class="style5">ie: 31st March, 2005</span> </td>
</tr>
<tr>
<td><span class="style4">INCLUDE NEWS STORY </span></td>
<td><span class="style5">CHECK BOX TO INCLUDE NEWS STORY IN NEWSLETTER</span></td>
</tr>
<c:forEach var="newsroom" items="${newsQueryResults.rows}" varStatus="status">
<tr>
<td> </td>
<td><input type="checkbox" name="chk_${newsroom.newsid}">
<span class="style4">${newsroom.newstitle}</span></td>
</tr>
</c:forEach>
<tr>
<td> </td>
<td><br><input type="submit" name="Submit" value="View Newsletter"></td>
</tr>
</table>
</form>
</body>
</html>

viewnewsletter.jsp+++++++++++++++++++++++++++++++++++++++++++++++++++

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="sql" uri="/jstl/sql" %>
<%@ taglib prefix="c" uri="/jstl/c" %>
<sql:query var="newsQueryResults" dataSource="jdbc/mysqldb" >select * from newsroom order by newsDate DESC limit 20</sql:query>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="viewnewsletter.php" method="post" enctype="multipart/form-data" name="view">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><span class="style4">${param.date} </span></td>
<td></td>
</tr>
<tr>
<td><span class="style4">${param.newsintro}</span></td>
<td</td>
</tr>
<c:forEach var="newsroom" items="${newsQueryResults.rows}" varStatus="status">
<c:if test="${param.chk_[newsroom.newsid] == 'on'}">
<cut value="${newsroom.newsid}"></cut>
<tr>
<td> </td>
<td><span class="style4"><cut value="${newsroom.newsid}" />stuff</span></td>
</tr>
</c:if>
</c:forEach>
<tr>
<td> </td>
<td><br><input type="submit" name="Submit" value="View Newsletter"></td>
</tr>
</table>
</form>
</body>
</html>


makenewsletter.php excerpt+++++++++++++++++++++++++++++++++++++++++++++

<td><input type="checkbox" name="php echo $row_addnewsprod['productId']; ?>">
<span class="style4">php echo $row_addnewsprod['title']; ?></span></td>




viewnewsletter.php excerpt+++++++++++++++++++++++++++++++++++++++++++++

do {
if($_POST[$row_thumbnails['productId']] == "on")
{echo"
{$row_thumbnails['productTitleDetails']}
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pulling out the relevant code:
This is on your first page, producing a number of checkboxes:


And this is the code that is meant to retrieve the values:



This is the offending expression:
${param.chk_[newsroom.newsid] == 'on'}

This looks up in the parameter list for a parameter called "chk_"
it then looks for a property/element of that variable indexed by newsroom.newsid. Not what you wanted to happen I think.

It is probably easiest to split this up into two steps:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Stefan for paring things down to the section of relavent code. Philip, it's best to do this yourself when posting code samples. Few people have the patience or time to wade through entire pages of JSP code.

Also please investigate the use of the UBB [CODE] tags. The CODE button under the text entry area helps you with this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!