我在使用JSF在Facelets中显示一些数据时遇到问题.我有一个哈希映射列表:
List<Map<String, String>> persons = new LinkedList<Map<String,String>>();
public List getPersons() {
return this.persons;
}
Run Code Online (Sandbox Code Playgroud)
我从数据库得到如下:
while(rs.next()) {
Map<String,String> result = new HashMap<String,String>();
result.put("name", rs.getString(1));
result.put("category", rs.getString(2));
this.persons.add(result);
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是如何在xhtml中显示每个地图的信息.我尝试使用ui:repeat但是错了所以我需要帮助.我必须得到名字和家人的吸气,但我该如何添加呢?
<ui:repeat value="#{class.persons}" var="persons">
<h:outputText value="#{persons['name'}"/>
<h:outputText value="#{persons['family'}"/>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
我希望你理解我的问题,并帮助我解决它.提前致谢!
我的问题是bean中参数的值为null
在xhtml中我有这个代码:
<h:commandLink action="#{navigation.editNews}" value="#{new.title}">
<f:param name="newsId" value="#{new.id}" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
在导航中,我重定向到news.xhtml
public String editNews(){
return "editNews";
}
Run Code Online (Sandbox Code Playgroud)
这是faces-config.xml中的代码
<navigation-case>
<from-action>#{navigation.editNews}</from-action>
<from-outcome>editNews</from-outcome>
<to-view-id>/news.xhtml</to-view-id>
<redirect />
</navigation-case>
Run Code Online (Sandbox Code Playgroud)
当我在news.xhtml中按下一个按钮时,我有一个bean调用方法,我尝试获取param,但它是null
FacesContext fc = FacesContext.getCurrentInstance();
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
String = params.get("newsId");
Run Code Online (Sandbox Code Playgroud)