Discussion:
How to use index in EL expression?
Kazuaki Miyauchi
2014-09-24 09:54:35 UTC
Permalink
Hi, it is also convenient to use the iteration of ELs such as
<c:if test="${!empty param.t${i}vorname}">.
Of course, it doesn't work. But, I'd like to do the following iteration.

<c:forEach var="i" begin="1" end="8">
<sql:update var="insert${i}">
insert into member values (1,?::integer,${i},?,?,?)
<sql:param value='${param.department}' />
<sql:param value='${teamid}' />
<sql:param value="${param.t${i}vorname}" />
<sql:param value="${param.t${i}name}" />
</sql:update>
</c:forEach>

Is there some idea for this without whole description expanding i?

Regards,
Stuart Thiel
2014-09-24 13:53:04 UTC
Permalink
Hello Kazuaki,

Very sorry for the response. I'm teaching this material right now and
assumed this was a student request (I have 70 of them) and only now
noticed that this was on the taglibs mailing list. Again, so sorry.
The "advice" in the prior is still sound, but now very out fo context.
The reasoning is still good.

I really think something in your domain layer should be parsing your
params and cleanly taking care of this all. You can still provide the
cleaned up POJOS via attributes, and that makes more sense. If you're
entirely skipping regular servlets and allowing direct access to JSP
you can probably use something like

${paramValues.key[i]}
Post by Kazuaki Miyauchi
Hi, it is also convenient to use the iteration of ELs such as
<c:if test="${!empty param.t${i}vorname}">.
Of course, it doesn't work. But, I'd like to do the following iteration.
<c:forEach var="i" begin="1" end="8">
<sql:update var="insert${i}">
insert into member values (1,?::integer,${i},?,?,?)
<sql:param value='${param.department}' />
<sql:param value='${teamid}' />
<sql:param value="${param.t${i}vorname}" />
<sql:param value="${param.t${i}name}" />
</sql:update>
</c:forEach>
Is there some idea for this without whole description expanding i?
Regards,
---------------------------------------------------------------------
--
Stuart Thiel, P. Eng.
Kazuaki Miyauchi
2014-09-25 09:03:32 UTC
Permalink
Post by Stuart Thiel
I really think something in your domain layer should be parsing your
params and cleanly taking care of this all. You can still provide the
cleaned up POJOS via attributes, and that makes more sense. If you're
entirely skipping regular servlets and allowing direct access to JSP
you can probably use something like
${paramValues.key[i]}
Using paramValues, it causes the same problem.
EL cannot be nested, so

<sql:param value="${paramValues.name[${i}]}" /> cannot be compiled.

I think we need pre-taglibs-taglibs or EL can be nested for resolving this.

Regards.
Stuart Thiel
2014-09-25 09:08:54 UTC
Permalink
Hello Kazuaki,
Can you not use i directly as you're already within el? I'm not sure
why you want to embed the el.

<sql:param value="${paramValues.name[i]}" />
Post by Kazuaki Miyauchi
Post by Stuart Thiel
I really think something in your domain layer should be parsing your
params and cleanly taking care of this all. You can still provide the
cleaned up POJOS via attributes, and that makes more sense. If you're
entirely skipping regular servlets and allowing direct access to JSP
you can probably use something like
${paramValues.key[i]}
Using paramValues, it causes the same problem.
EL cannot be nested, so
<sql:param value="${paramValues.name[${i}]}" /> cannot be compiled.
I think we need pre-taglibs-taglibs or EL can be nested for resolving this.
Regards.
---------------------------------------------------------------------
--
Stuart Thiel, P. Eng.
Kazuaki Miyauchi
2014-09-25 09:14:28 UTC
Permalink
Hello Stuart,
Post by Stuart Thiel
Can you not use i directly as you're already within el? I'm not sure
why you want to embed the el.
< sql:param value="${paramValues.name[i]}" />
Because we need to specify i concretely for getting data in above case.
Post by Stuart Thiel
Hello Kazuaki,
Can you not use i directly as you're already within el? I'm not sure
why you want to embed the el.
<sql:param value="${paramValues.name[i]}" />
Post by Kazuaki Miyauchi
Post by Stuart Thiel
I really think something in your domain layer should be parsing your
params and cleanly taking care of this all. You can still provide the
cleaned up POJOS via attributes, and that makes more sense. If you're
entirely skipping regular servlets and allowing direct access to JSP
you can probably use something like
${paramValues.key[i]}
Using paramValues, it causes the same problem.
EL cannot be nested, so
<sql:param value="${paramValues.name[${i}]}" /> cannot be compiled.
I think we need pre-taglibs-taglibs or EL can be nested for resolving this.
Regards.
---------------------------------------------------------------------
--
Stuart Thiel, P. Eng.
---------------------------------------------------------------------
Peter Wagner
2014-09-25 10:00:28 UTC
Permalink
Hello,


use a temporary variable as an “index”:





<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>

<head>

<title>EL Test</title>

</head>


<body>

<c:forEach var="i" begin="1" end="10">

<c:set var="paramName" value="vorname${i}"/>

${param[paramName]}<br/>

</c:forEach>

</body>

</html>




Regards, Peter
Kazuaki Miyauchi
2014-10-02 09:06:25 UTC
Permalink
Thanks a lot!
I'll check its correctly working.

Regards, K. Miyauchi
Post by Peter Wagner
Hello,
<html>
<head>
<title>EL Test</title>
</head>
<body>
<c:forEach var="i" begin="1" end="10">
<c:set var="paramName" value="vorname${i}"/>
${param[paramName]}<br/>
</c:forEach>
</body>
</html>
Regards, Peter
Kazuaki Miyauchi
2014-10-06 01:05:19 UTC
Permalink
Hi. Peter.

It works well. Thank you very much!
EL is fantastic!

And now I have one more question.
var parameter doesn't seem to accept EL description as following.

<c:forEach var="i" begin="1" end="8">
<sql:update var="insert${i}">

Is there a smart way to resolve above description?

Regards, K.Miyauchi
Peter Wagner
2014-10-06 06:39:51 UTC
Permalink
Hi,
Post by Kazuaki Miyauchi
<sql:update var="insert${i}">
Is there a smart way to resolve above description?
This is not possible. I'd suggest to use beans instead.
Also, I would recommend to avoid using sql:update under any circumstances.

Regards, Peter
Kazuaki Miyauchi
2014-10-06 08:15:26 UTC
Permalink
Post by Peter Wagner
Also, I would recommend to avoid using sql:update under any circumstances.
That causes some problems?
I think dbtags are the most powerful tools for developing Web-DB programs.
Why did developers stop creating this powerful functions?

Regards, K.Miyauchi

Loading...