【问题标题】:List doesn't get populated in p:dataTable on click of p:menuitem单击 p:menuitem 时列表未填充到 p:dataTable 中
【发布时间】:2015-02-09 10:07:22
【问题描述】:

我正在使用一个 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>

请帮忙。

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    在您发布的代码中,您不会更改 List&lt;MsgType&gt; msgValList 的值,而只会更改 ActionListener 中同名的某个本地列表的值。

    此外,ActionListener 方法的类型应为 Stringvoid

    如果需要在 AJAX 调用后更新/重新呈现您的数据表以查看 ActionListener 所做的更改。

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

    【讨论】:

    • :我确实将动作侦听器方法更改为 void 并开始使用在类级别声明的列表想要如何继续使用 AJAX。如果您指导我,将会有很大帮助。我是 JSF 的新手。
    • 我不确定您评论中的问题。要在 AJAX 调用后更新数据表,只需将 update="dataTbl" 添加到您的菜单项
    • 您能否告诉我更多关于如何进行 AJAX 调用的信息。在我的菜单项中有多个项目,所以我必须为所有人添加更新。
    • 你已经在这样做了。单击菜单项时,将通过 AJAX 调用 actionListener 方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    • 1970-01-01
    • 2014-03-26
    • 2012-10-05
    • 2012-03-22
    相关资源
    最近更新 更多