我想有条件地输出一些Facelets代码.
为此,JSTL标签似乎工作正常:
<c:if test="${lpc.verbose}">
...
</c:if>
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?
首先,我是Java EE的新手,来自强大的ASP .NET开发背景.我已经浏览了网络,我可能会错过这个,但似乎没有关于如何将支持bean类连接到JSF组件的简单直接的教程.
一个很好的例子是这样的,目前我正在尝试创建一个JSF页面,其中有一组链接作为菜单栏和一组表单.我打算做的是,当点击一个链接时,将呈现一个特定的表单.
在ASP.NET中,我可以轻松检索元素,然后将属性设置为可显示.我想知道在JSF中是否有简单的方法(哎呀,甚至任何方式).
表单已经在页面中,只需在单击特定链接时将"render"属性设置为true即可.
使用JSF和EL,我基本上试图检查变量是否为null(或不是).
这是一段代码:
<p:dataGrid value="#{bean.graphiques}"
var="graphique"
rows="1" columns="3">
<c:if test="#{not empty graphique}">
<p:chart type="line" model="#{graphique}"/>
</c:if>
<c:if test="#{empty graphique}">
<p:outputLabel>
Add a new chart.
</p:outputLabel>
</c:if>
</p:dataGrid>
Run Code Online (Sandbox Code Playgroud)
首先检查,#{not empty graphique}
总是假,即使graphique
不是null.我试着用#{graphique ne null}
和#{graphique != null}
,但它是假的,太.
删除c:if
语句后,将显示图表.因此,graphique
不是空的.
我在很多网站上寻找解决方案 - 包括SO - 但是没有设法找到解决方案.
你知道发生了什么以及如何解决我的问题吗?
谢谢!
我有一个JSF项目的问题.
我正在尝试显示包含请求标头字段的表.因此我写了这个托管bean:
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
@ManagedBean
@RequestScoped
public class RequestHeader extends LinkedHashMap<String, List<String>> {
private List<String> keys;
@PostConstruct
public void init() {
final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
keys = Collections.list(request.getHeaderNames());
for (final String key : keys) {
final List<String> value = Collections.list(request.getHeaders(key));
final List<String> oldValue = get(key);
if (oldValue == null) {
put(key, value);
} else {
oldValue.addAll(value);
}
}
} …
Run Code Online (Sandbox Code Playgroud)