Java 如何在 jsf 呈现的属性中指定来自 2 个不同 bean 的条件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1004382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:08:57  来源:igfitidea点击:

How do I specify conditions from 2 different beans in a jsf rendered attribute?

javajsfrendered-attribute

提问by rojoca

I want to do something along the lines of the following but when I use it like this I get a parse error telling me an entity needs to directly follow the '&' character:

我想按照以下方式做一些事情,但是当我像这样使用它时,我收到一个解析错误,告诉我一个实体需要直接跟随“&”字符:

<ice:selectManyCheckbox
rendered="#{!bean1.condition1 && bean2.condition2}"
value="#{bean1.selected}">
<f:selectItems value="#{bean2.items}" />
</ice:selectManyCheckbox>

How can I get rendered to check conditions from 2 different beans?

如何渲染以检查来自 2 个不同 bean 的条件?

采纳答案by karim79

Use 'and' instead:

改用“和”:

<ice:selectManyCheckbox rendered="#{!bean1.condition1 and bean2.condition2}" value="#{bean1.selected}">

回答by Romain Linsolas

karim79 is right, you can just use the andoperator.

karim79 是对的,您可以使用and运算符。

In addition to that, you can have a look to this page, which explains the Expression Language (EL) with several examples...

除此之外,你可以看看这个页面,它用几个例子解释了表达式语言(EL)......

回答by snehasish

Maybe you are using facelets which assumes every jsp page after compilation is a xml file. And you know in an xml file you have to provide an xml entity name just after the &symbol. So to escape this situation use &amp;in place of &.

也许您正在使用 facelets,它假定编译后的每个 jsp 页面都是一个 xml 文件。您知道在 xml 文件中,您必须在&符号后提供一个 xml 实体名称。因此,要摆脱这种局面的使用&amp;代替&