英文:
String concatenation for passing parameters in action clause
问题
在一个 XHTML 页面中,我需要将一个参数传递给一个 Bean 方法,但我无法弄清楚如何传递一个由一些文字和来自表列的值拼接而成的字符串。
我写了:
<p:commandButton action = "Combos.Students('T.StudentID=\''+result.STUDENTID+'\'')" />
但是它报错了:
java.lang.NumberFormatException: For input string: "T.StudentID"
即使两个字符串被拼接在一起,也会出现相同的错误:
<p:commandButton action = "Combos.Students('T.StudentID ' + ' abc ' )" />
方法:
public void getValues (String s) {
System.out.println("s : " + s);
}
调用产生错误(使用表列的值或任何内容):
<p:commandButton action = "#{Combos.getValues('T.StudentID='+result.STUDENTNAME)}"/>
没有错误的调用:
<p:commandButton action = "#{Combos.getValues('T.StudentID=')}"/>
英文:
in an xhtml page, i need to pass a parameter to a bean method but i can't figure out how to pass a concatenated string having some literals and value from table column
i wrote
<p:commandButton action = "Combos.Students('T.StudentID=\''+result.STUDENTID+'\'')" />
but it gives error
java.lang.NumberFormatException: For input string: "T.StudentID"
event if two strings are concatenated, same error occurs
<p:commandButton action = "Combos.Students('T.StudentID ' + ' abc ' )" />
The Method
public void getValues (String s) {
System.out.println("s : " + s);
}
Call producing error (using a table column value or even any thing)
<p:commandButton action = "#{Combos.getValues('T.StudentID='+result.STUDENTNAME)}"/>
Call having no error
<p:commandButton action = "#{Combos.getValues('T.StudentID=')}"/>
答案1
得分: 0
感谢@Kalanj Djordje Djordje在这篇帖子https://stackoverflow.com/questions/5993774/numberformatexception-when-trying-to-concatenate-a-string-in-el中的回答,不仅我找到了解决方案,而且解决方案非常出色。我的最终代码如下:
<p:commandButton action = "Combos.Students('T.StudentID=\''.concat(result.FieldName)).concat('\''" />
英文:
Thanx to @Kalanj Djordje Djordje in a post https://stackoverflow.com/questions/5993774/numberformatexception-when-trying-to-concatenate-a-string-in-el
where not only i found the solution but also it was excellent. my final code is
<p:commandButton action = "Combos.Students('T.StudentID=\''.concat(result.FieldName)).concat('\''" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论