JSF PrimeFaces 渲染组件
JSF PrimeFaces rendering components
假设我有一个简单的方法,就像这样:
public String test()
{
return "hello";
}
现在假设我有以下 PrimeFace 组件:
<p:fieldset styleClass="containers" rendered="#{controller.test()}">
<h2>Testing</h2>
<p:outputLabel for="test" value="Test" />
<p:inputText id="test" />
</p:fieldset>
上面的方法returns "hello"。我想通过将该方法的 returned 值与我的一个 bean 的字段进行比较来动态显示和隐藏该 fieldSet。例如,在呈现的参数上,我想做类似的事情:controller.test() != "some variable" 这将 return 真或假。我可以这样做吗?如果不是,那是什么方法呢?
基本上,目标是通过比较方法的 returned 值与 bean 属性.
来动态显示和隐藏一些容器
看来你误会了rendered
渲染的属性
A component tag uses a Boolean EL expression, along with the rendered
attribute, to determine whether or not the component will be rendered.
如果你检查上面的定义,你就会知道这个属性的确切用途。
更多你可以在下面看到
The rendered attribute which uses Boolean EL expression indicates
whether a component is currently visible or not. The property is
useful when you want to hide components for specific users or based on
condition. The default value of rendered attribute is true.
<h:outputText value=”mapping” rendered=”Boolean EL expression” />
例如,如果购物车不包含任何项目,则不会呈现页面以下部分中的 commandLink 组件:
<h:commandLink id="check"
...
rendered="#{cart.numberOfItems > 0}">
<h:outputText
value="#{bundle.CartCheck}"/>
</h:commandLink>
根据你的具体问题,你可以这样做
- 进行
String
变量调用 value
- 现在为上述变量
创建get/set方法
现在在你的测试方法中你可以添加
public void test(){
value="hello";
}
记住你调用了 test()
页面加载方法
现在在您的 Xhtml 或 Jsf 或 Jsp 页面中
rendered="#{controller.value != 'hello'}"
或者更好的方法是创建一个 Boolean
变量并执行隐藏和显示组件的所有魔法
假设我有一个简单的方法,就像这样:
public String test()
{
return "hello";
}
现在假设我有以下 PrimeFace 组件:
<p:fieldset styleClass="containers" rendered="#{controller.test()}">
<h2>Testing</h2>
<p:outputLabel for="test" value="Test" />
<p:inputText id="test" />
</p:fieldset>
上面的方法returns "hello"。我想通过将该方法的 returned 值与我的一个 bean 的字段进行比较来动态显示和隐藏该 fieldSet。例如,在呈现的参数上,我想做类似的事情:controller.test() != "some variable" 这将 return 真或假。我可以这样做吗?如果不是,那是什么方法呢?
基本上,目标是通过比较方法的 returned 值与 bean 属性.
来动态显示和隐藏一些容器看来你误会了rendered
渲染的属性
A component tag uses a Boolean EL expression, along with the rendered attribute, to determine whether or not the component will be rendered.
如果你检查上面的定义,你就会知道这个属性的确切用途。
更多你可以在下面看到
The rendered attribute which uses Boolean EL expression indicates whether a component is currently visible or not. The property is useful when you want to hide components for specific users or based on condition. The default value of rendered attribute is true.
<h:outputText value=”mapping” rendered=”Boolean EL expression” />
例如,如果购物车不包含任何项目,则不会呈现页面以下部分中的 commandLink 组件:
<h:commandLink id="check"
...
rendered="#{cart.numberOfItems > 0}">
<h:outputText
value="#{bundle.CartCheck}"/>
</h:commandLink>
根据你的具体问题,你可以这样做
- 进行
String
变量调用value
- 现在为上述变量 创建get/set方法
现在在你的测试方法中你可以添加
public void test(){
value="hello";
}
记住你调用了 test()
页面加载方法
现在在您的 Xhtml 或 Jsf 或 Jsp 页面中
rendered="#{controller.value != 'hello'}"
或者更好的方法是创建一个 Boolean
变量并执行隐藏和显示组件的所有魔法