我想有条件地输出一些Facelets代码.
为此,JSTL标签似乎工作正常:
<c:if test="${lpc.verbose}">
...
</c:if>
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?
我在页面上使用datatable并使用绑定属性将其绑定到我的支持bean.这是我的代码: -
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:dataTable var="item" value="#{testBean.stringCollection}" binding="#{testBean.dataTable}">
<h:column>
<h:outputText value="#{item}"/>
</h:column>
<h:column>
<h:commandButton value="Click" actionListener="#{testBean.action}"/>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的豆子: -
package managedBeans;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlDataTable;
@ManagedBean(name="testBean")
@ViewScoped
public class testBean implements Serializable {
private List<String> stringCollection;
public List<String> getStringCollection() {
return stringCollection;
}
public void …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSF 2.0(过去几个月使用ICEfaces 1.8之后),我试图找出为什么在JSF 2.0中我的支持bean构造函数被多次调用.
bean应该在创建时实例化一次,但每当我单击commandButton时,就会显示"Bean Initialized"文本,指示一个新的Bean对象被实例化.
facelet页面:
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<div id="content">
<h:form id="form">
<h:commandButton value="Toggle" action="#{bean.toggleShowMe}"/>
</h:form>
<h:panelGrid rendered="#{bean.showMe}">
<h:outputText value="Show me!"/>
</h:panelGrid>
</div>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
支持bean:
@ManagedBean
@RequestScoped
public class Bean {
private boolean showMe = false;
public boolean isShowMe() {
return showMe;
}
public void setShowMe(boolean showMe) {
this.showMe = showMe;
}
public void toggleShowMe(){
System.out.println(showMe);
if(showMe==true){
showMe=false;
}else{
showMe=true;
}
}
/** Creates a new instance of Bean */
public Bean() …Run Code Online (Sandbox Code Playgroud) 我想将参数从一个页面传递到另一个页面.
每个页面都有一个ViewScoped JSF Backing Bean.
虽然,我尝试使用<f:param>我得到以下错误:当我点击<h:commandLink>将导航到另一个页面.
错误:
] Root cause of ServletException.
com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean ReservationActionBean. The following problems were found:
- The scope of the object referenced by expression #{param.resvDataModel}, request, is shorter than the referring managed beans (ReservationActionBean) scope of view
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:265)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
.........
Run Code Online (Sandbox Code Playgroud)
page1.xhtml
<p:panelGrid style="margin-top:-1px;" id="dashboard">
<ui:repeat value="#{DashBoard.dayList}" var="day">
<p:row>
<p:column style="background:#C1CDCD;width:100px;">
<h:outputText value="#{day}" style="color:#333333;font-size:13px;">
<f:convertDateTime type="date" pattern="EEE, yyyy-MM-dd"/>
</h:outputText> …Run Code Online (Sandbox Code Playgroud)