单击 p:menuitem 后,列表不会填充到 p:dataTable 中

List doesn't get populated in p:dataTable on click of p:menuitem

我正在使用 PanelMenu 和来自 primefaces 的数据表。 要求的是,当用户点击菜单项时,应在数据中填充相应的数据。

我的 POC: 我能够在托管 bean 中单击菜单项。

问题:

它确实达到了所需的方法,但数据表中没有填充所需的结果集。 下面是一段代码。

 @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>

请帮忙。

在您发布的代码中,您不会更改 List<MsgType> msgValList 的值,而只会更改 ActionListener 中具有相同名称的某些本地列表的值。

此外,ActionListener-methods 的类型应为 Stringvoid

如果需要 update/rerender 您的数据表在 AJAX 调用后查看 ActionListener 所做的更改。

顺便说一句,您的 ActionListener 方法的名称表明它是一个 getter 方法。这不是真正的问题,但您应该使用更合适的名称。