我正在使用PanelMenu和来自primefaces的数据表。 要求是当用户点击menuitem时应该在数据中填充相应的数据。
我的POC: 我可以在Managed bean中点击menuitem。
问题:
它确实达到了所需的方法,但数据表没有填充所需的结果集。 下面是一段代码。
@ManagedBean(name="msgTpye")
@SessionScoped
public class MsgType implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3167238749130750720L;
/**
*
*/
private String msgdesription="";
private String msgtag="";
private String msgVal="";
private List<MsgType> msgValList;
public MsgType(){
}
public MsgType (String msgdesription,String msgtag,String msgVal ){
this.msgdesription=msgdesription;
this.msgtag=msgtag;
this.msgVal=msgVal;
}
public List<MsgType> getMsgTypeList(ActionEvent event){
String msgType = (String) event.getComponent().getAttributes().get("msgTypeParam");
System.out.println("sss"+msgType);
List<MsgType> msgValList = new ArrayList<MsgType>();
if("FREETEXT".equals(msgType)){
msgValList.add(new MsgType(" ","{1100}", "30T N"));
msgValList.add(new MsgType(""," {1110}"," 10111353FT01"));
msgValList.add(new MsgType(""," {1120}" ,"20121011G1QX370C00004810111353FT01"));
msgValList.add(new MsgType(""," {1500}"," 30ABCDEFGHP" ));
msgValList.add(new MsgType("","{1510} ","1000"));
msgValList.add(new MsgType("","{1520}"," 20121011J1Q504AC000001"));
msgValList.add(new MsgType(""," {2000}"," 000000000[AMOUNT]"));
msgValList.add(new MsgType("","{3100}", "101003317FST NATL BK KS*"));
msgValList.add(new MsgType("","{3320}"," [REFERENCE]*"));
msgValList.add(new MsgType("","{3400}" ,"101102315MARSHALL & ILSLEY*"));
msgValList.add(new MsgType("","{3600}"," CTR"));
msgValList.add(new MsgType("","{4100}", "D987543*RIVA BANK*10000 COLLEGE BLVD., STE. 260*OVERLAND OFAC PARK, KS 66210-1400*"));
msgValList.add(new MsgType("","{4200}"," D101004028651*KOESTEN, HIRSCHMANN & CRABTREE,*INC.*FLEXIBLE BENEFIT PLAN*"));
msgValList.add(new MsgType("","{5000}", "D077755*KOESTEN HIRSCHMANN & CRABTREE, INC.*10000 COLLEGE BLVD., STE. 260*OVERLAND OFAC PARK, KS 66210-1400*$"));
msgValList.add(new MsgType("Receiver FI Information ","{6100}" ,"D987543*[NAME]*10000 COLLEGE BLVD., STE. 260*OVERLAND OFAC PARK, KS 66210-1400*"));
}else {
msgValList.add(new MsgType("No Data ", "No data", "No Data"));
}
return msgValList;
}
}
我的xhtml页面:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet library="css" name="default.css" />
<h:outputStylesheet library="css" name="cssLayout.css" />
</h:head>
<h:body>
<br/>
<h:form style="width:100%;position:absolute;left:5%;top:22%;border:none">
<p:panelMenu style="width:100%;align:left">
<p:submenu label="#{msg.FREETEXT}" >
<p:menuitem value="#{msg.FREETEXT}" actionListener="#{msgTpye.getMsgTypeList}" icon="ui-icon-document" >
<f:attribute name="msgTypeParam" value="FREETEXT" />
</p:menuitem>
</p:submenu>
</p:panelMenu>
<p:dataTable id="dataTbl" var="value" value="#{msgTpye.msgValList}" style="width:100%; align:center;">
<p:column headerText="#{msg.Tag}">
<h:outputText value="#{value.msgtag}" />
</p:column>
<p:column headerText="#{msg.Description}">
<h:outputText value="#{value.msgdesription}" />
</p:column>
<p:column headerText="#{msg.Values}">
<h:outputText value="#{value.msgVal}" />
</p:column>
<p:column headerText="#{msg.Editable}"></p:column>
</p:dataTable>
</h:form>
请帮忙。
答案 0 :(得分:2)
在您发布的代码中,您不会更改List<MsgType> msgValList
的值,而只会更改ActionListener中具有相同名称的某些本地List的值。
此外,ActionListener方法应为String
或void
类型。
如果在AJAX调用后需要更新/重新呈现数据表,以查看ActionListener所做的更改。
顺便说一下,ActionListener方法的名称表明它是一个getter方法。这不是一个真正的问题,但您应该使用更合适的名称。