我从 JSF 开始,并试图让下面的简单示例正常工作,但它只显示一个空矩形
java bean代码是:
import javax.faces.model.SelectItem;
import java.util.*;
public class SItemsBean
{
private List options;
public SItemsBean()
{
options = new ArrayList();
SelectItem option = new SelectItem("ch1", "choice1", "This bean is for selectItems tag", true);
options.add(option);
option = new SelectItem("ch2", "choice2");
options.add(option);
option = new SelectItem("ch3", "choice3");
options.add(option);
option = new SelectItem("ch4", "choice4");
options.add(option);
option = new SelectItem("ch5", "choice5");
options.add(option);
}
public void setOptions(List opt)
{
options = opt;
}
public List getOptions()
{
return options;
}
}
xhtml代码是:
<h:form>
<h:outputText value="Select choices given below :"/><br/><br/>
<h:selectManyListbox id="subscriptions" value="#{SItemsBean.options}" size="3">
<f:selectItems value="#{SItemsBean.options}" />
</h:selectManyListbox>
</h:form>
并在 faces-config.xml 中附加以下内容:
<managed-bean>
<managed-bean-name>sItemsBean</managed-bean-name>
<managed-bean-class>sItemsBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<display-name>options</display-name>
<property-class>java.util.List</property-class>
</managed-property>
</managed-bean>