字符串拼接以在动作子句中传递参数

huangapple go评论93阅读模式
英文:

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('\''" />

huangapple
  • 本文由 发表于 2020年9月10日 17:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63826954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定