JSTL - 将错误字符串转换为 Long
JSTL - Cast Error String to Long
我正在尝试使用 JSTL
与值进行比较,但我遇到了这个错误。
An error occurred while evaluating custom action attribute "value"
with value "${item.ruleValues.size}": The "." operator was supplied
with an index value of type "java.lang.String" to be applied to a List
or array, but that value cannot be converted to an integer. (null)
这是具体的代码行 -
<c:set var="nElCol" value="0" scope="page"/>
<c:forEach var="elem" items="${item.ruleValues}" varStatus="status">
<c:set var="size" value="${item.ruleValues.size}" scope="page" />
<c:set var="nElCol" value="${nElCol + 1}" scope="page"/>
<c:if test="${size == (nElCol-1)}">
<TD align="center" width="110">
<input id='<c:out value="${count}" />' type="text" name="fname" value='<c:out value="${elem}"/>'>
</TD>
<TD align="center" width="110">
<img src="/XA-IME-PF/public/img/Plus.jpg" alt="add" width="10" height="10"/>
</TD>
</c:if>
</c:forEach>
item
对象是这个:
public class BoElementToPrint implements Serializable{
private List ruleValues;
/**
* @return
*/
public List getRuleValues() {
return ruleValues;
}
/**
* @param list
*/
public void setRuleValues(List list) {
ruleValues = list;
}
}
ruleValues
是一个字符串列表。
您必须使用 JSTL 函数 taglib,才能评估 List
的大小。 .
运算符仅用于引用 bean 属性或哈希映射键。
因此,您必须先导入标签库:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
然后更改 size
定义:
<c:set var="size" value="${fn:length(item.ruleValues)}" scope="page" />
在更新的 EL 版本中,我相信您可以简单地执行以下操作:
${item.ruleValues.size()}
即。 append () 否则 EL 解析器将寻找方法 getSize();
看这里:
https://whosebug.com/tags/el/info
Invoking non-getter methods
Since EL 2.2, which is maintained as part of Servlet 3.0 / JSP 2.2
(Tomcat 7, Glassfish 3, JBoss AS 6, etc), it's possible to invoke
non-getter methods, if necessary with arguments.
e.g.
${bean.find(param.id)} with
public Something find(String id) {
return someService.find(id); } will invoke the method with request.getParameter("id") as argument.
我正在尝试使用 JSTL
与值进行比较,但我遇到了这个错误。
An error occurred while evaluating custom action attribute "value" with value "${item.ruleValues.size}": The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer. (null)
这是具体的代码行 -
<c:set var="nElCol" value="0" scope="page"/>
<c:forEach var="elem" items="${item.ruleValues}" varStatus="status">
<c:set var="size" value="${item.ruleValues.size}" scope="page" />
<c:set var="nElCol" value="${nElCol + 1}" scope="page"/>
<c:if test="${size == (nElCol-1)}">
<TD align="center" width="110">
<input id='<c:out value="${count}" />' type="text" name="fname" value='<c:out value="${elem}"/>'>
</TD>
<TD align="center" width="110">
<img src="/XA-IME-PF/public/img/Plus.jpg" alt="add" width="10" height="10"/>
</TD>
</c:if>
</c:forEach>
item
对象是这个:
public class BoElementToPrint implements Serializable{
private List ruleValues;
/**
* @return
*/
public List getRuleValues() {
return ruleValues;
}
/**
* @param list
*/
public void setRuleValues(List list) {
ruleValues = list;
}
}
ruleValues
是一个字符串列表。
您必须使用 JSTL 函数 taglib,才能评估 List
的大小。 .
运算符仅用于引用 bean 属性或哈希映射键。
因此,您必须先导入标签库:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
然后更改 size
定义:
<c:set var="size" value="${fn:length(item.ruleValues)}" scope="page" />
在更新的 EL 版本中,我相信您可以简单地执行以下操作:
${item.ruleValues.size()}
即。 append () 否则 EL 解析器将寻找方法 getSize();
看这里:
https://whosebug.com/tags/el/info
Invoking non-getter methods
Since EL 2.2, which is maintained as part of Servlet 3.0 / JSP 2.2 (Tomcat 7, Glassfish 3, JBoss AS 6, etc), it's possible to invoke non-getter methods, if necessary with arguments.
e.g.
${bean.find(param.id)} with
public Something find(String id) { return someService.find(id); } will invoke the method with request.getParameter("id") as argument.