繁体   English   中英

PrimeFaces 数据表:ajax 捕获过滤器事件但不捕获排序事件

[英]PrimeFaces dataTable: ajax catches filter event but not sort event

我能够捕获过滤器事件并调用支持 bean 中的函数,但是使用类似的代码我无法捕获排序事件。 奇怪的是,我有几页“完全”相同并且工作得很好。 当我尝试按任何列排序时,dataTable 根本不会对鼠标单击做出反应。 不会调用支持 bean 排序侦听器,但会调用过滤器侦听器。

在此先感谢您的帮助。

在下面的代码中,TemplateBasic.xhtml 只是在 h:form 中插入“内容”

这是 xhtml :(ajax 命令大约在中间,就在 dataTable 的末尾之前)

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                template="/TemplateBasic.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui">

  <ui:define name="content">

    <table>
      <tr>
        <td><p:graphicImage url="#{resource['images/goldCup3small.jpg']}" height="30" /></td>
        <td><h2>#{listStandingsBean.getChampionshipsStandingsTitle()}</h2></td>
        <td><p:graphicImage url="#{resource['images/goldCup3small.jpg']}" height="30" /></td>
      </tr>
    </table>

    <p:dataTable id="standingsList"
                 var="item" 
                 value="#{listStandingsBean.standings}" 
                 widgetVar="standingsTable"
                 emptyMessage="#{mainBean.getListEmptyMsg()}" 
                 filteredValue="#{listStandingsBean.filteredStandings}"
                 style="white-space: pre-line; font-stretch: condensed; width: 100%; padding: 0px" 
                 scrollable="true"
                 scrollRows="20"
                 scrollHeight="250"
                 scrollWidth="90%"
                 liveScroll="false"
                 resizableColumns="true"
                 rowIndexVar="rowIndex"
                 >

      <f:facet name="header">
        <p:outputPanel>
          <h:outputText value="#{mainBean.getSearchAllFieldsLabel()}" />
          <p:inputText id="globalFilter" 
                       onkeyup="PF( 'standingsTable' ).filter()" 
                       style="width:150px" 
                       placeholder="#{mainBean.getEnterKeywordPlaceholder()}"/>

          <p:commandButton actionListener="#{listStandingsBean.clickReturn()}"
                           icon="fa fa-fw fa-arrow-left"
                           title="#{mainBean.getReturnButtonTitle()}"
                           onclick="PF('dlgWait').show();"
                           ajax="true"
                           style="float: left"/>

        </p:outputPanel>
      </f:facet>

      <p:column headerText="#{listStandingsBean.getRowTxt()}" 
                footerText="#{listStandingsBean.getRowTxt()}" 
                width="10" style="text-align: center">
        <h:outputText value="#{rowIndex+1}" />
      </p:column>

      <p:column filterBy="#{item.id.year}" 
                sortBy="#{item.id.year}" 
                headerText="#{listStandingsBean.getYearTxt()}" 
                footerText="#{listStandingsBean.getYearTxt()}" 
                filterMatchMode="exact" width="70" style="text-align: center; padding: 1px">
        <f:facet name="filter">
          <p:spinner size="3" value="#{listStandingsBean.currYear}"
                     onchange="PF( 'standingsTable' ).filter()"
                     styleClass="year-spinner" >
            <f:converter converterId="javax.faces.Integer" />
          </p:spinner>
        </f:facet>
        <h:outputText value="#{item.id.year}"/>
      </p:column>

      <p:column filterBy="#{listStandingsBean.getUserName( item.id.user )}"
                sortBy="#{listStandingsBean.getUserName( item.id.user )}"
                headerText="#{listStandingsBean.getUserTxt()}" 
                footerText="#{listStandingsBean.getUserTxt()}" 
                filterMatchMode="contains" width="120" style="white-space: pre-line; padding: 2px">
        <f:facet name="filter">  
          <p:inputText size="10" onkeyup="PF( 'standingsTable' ).filter()" /> 
        </f:facet>
        <h:outputText value="#{listStandingsBean.getUserName( item.id.user )}" />
      </p:column>

      <p:column filterBy="#{item.id.level}" 
                sortBy="#{item.id.level}" 
                headerText="#{listStandingsBean.getLevelTxt()}" 
                footerText="#{listStandingsBean.getLevelTxt()}" 
                filterMatchMode="contains" width="70" style="padding: 2px">
        <f:facet name="filter" >
          <p:selectOneMenu onchange="PF( 'standingsTable' ).filter()">
            <f:selectItem noSelectionOption="true"  />
            <f:selectItems value="#{listStandingsBean.levels}"  />
          </p:selectOneMenu>
        </f:facet>
        <h:outputText value="#{listStandingsBean.getLevelName( item.id.level )}" />
      </p:column>

      <p:column filterBy="#{listStandingsBean.getChampionshipName( item )}" 
                sortBy="#{listStandingsBean.getChampionshipName( item )}" 
                headerText="#{listStandingsBean.getChampionshipTxt()}" 
                footerText="#{listStandingsBean.getChampionshipTxt()}" 
                filterMatchMode="contains" width="130" style="white-space: pre-line; padding: 2px">
        <h:outputText value="#{listStandingsBean.getChampionshipName( item )}" />
      </p:column>

      <p:column sortBy="#{item.pointsSd+item.pointsRd}" 
                style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getSR_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getSR_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSd+item.pointsRd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsSd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getS_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getS_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSd}" />
      </p:column>

      <p:column sortBy="#{item.pointsRd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getR_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getR_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsRd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsEd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getE_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getE_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsEd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsSo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getS_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getS_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSo}" />
      </p:column>

      <p:column sortBy="#{item.pointsRo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getR_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getR_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsRo}"/>
      </p:column>

      <p:column sortBy="#{item.pointsEo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getE_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getE_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsEo}"/>
      </p:column>
      <p:ajax event="filter" update="contentForm:graphsAccordion"
              listener="#{listStandingsBean.filterEvent}"/>
      <p:ajax event="sort" update="contentForm:graphsAccordion"
              listener="#{listStandingsBean.sortEvent}" />
    </p:dataTable>

    <p:remoteCommand name="onCompleteAuto" oncomplete="PF('standingsTable').filter()" autoRun="true" />

    <p:accordionPanel id="graphsAccordion" 
                      widgetVar="graphsAccordion"
                      multiple="true"
                      activeIndex="-1"
                      style="width:90%" >
      <p:tab title="#{listStandingsBean.getSR_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSRD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(0)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getS_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(1)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getR_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartRD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(2)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getE_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartED"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(3)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getS_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(4)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getR_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartRO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(5)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getE_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartEO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(6)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>
    </p:accordionPanel>


  </ui:define>


</ui:composition>

和支持 Bean:

@ManagedBean( name = "listStandingsBean" )
@ViewScoped
public class ListStandingsBean {

  @ManagedProperty( value = "#{mainBean}" )
  private MainBean mainBean;

  private ModelForView theModel;
  private Controller theController;

  private List<Standings> standings;
  private List<Standings> filteredStandings;
  private Long index = 0L;
  private HorizontalBarChartModel horizontalBarModel[];

  /**
   * Creates a new instance of StandingsBean
   */
  public ListStandingsBean() {
    horizontalBarModel = new HorizontalBarChartModel[ 7 ];
  }

  public MainBean getMainBean() {
    return mainBean;
  }

  public void setMainBean( MainBean mainBean ) {
    this.mainBean = mainBean;
  }

  @PostConstruct
  public void init() {
    theModel = mainBean.getModel();
    theController = mainBean.getController();
    index = 0L;
    standings = theModel.getStandings();
  }

  //
  // queries
  //
  public Integer getCurrYear() {
    Calendar c = new GregorianCalendar();
    return c.get( Calendar.YEAR );
  }

  public void setCurrYear( Integer y ) {
  }

  public void setStandings( List<Standings> standings ) {
    this.standings = standings;
  }

  public List<Standings> getStandings() {
    return standings;
  }

  public Long getIndex() {
    return ++index;
  }

  public List<Byte> getLevels() {
    Byte levels[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
    return Arrays.asList( levels );
  }

  public List<Standings> getFilteredStandings() {
    index = 0L;
    return filteredStandings;
  }

  public void setFilteredStandings( List<Standings> filteredStandings ) {
    this.filteredStandings = filteredStandings;

    this.updateCharts();
  }

  /*
   * user actions
   */
  public void clickReturn() {
    theController.clickReturn( UI.LIST_STANDINGS );
  }

  public void updateCharts() {
    for( int chMode = 0; chMode < 7; chMode++ ) {

      HorizontalBarChartModel model = new HorizontalBarChartModel();
      model.setShadow( false );
      model.setZoom( false );
      model.setMouseoverHighlight( false );
//    model.setLegendCols( 4 );
      model.setAnimate( false );
      model.setMouseoverHighlight( true );
      model.setBarMargin( 0 );
      model.setBarPadding( 1 );
//    model.setLegendPlacement( LegendPlacement.OUTSIDE );
//    model.setExtender( "standingsChartExtender" );
//    model.setLegendPosition( "ne" );
      model.setShowPointLabels( true );
      model.setShowDatatip( false );
      model.getAxes()
        .put( AxisType.Y, new CategoryAxis( "Driver Level_Championship" ) );
      Axis xAxis = model.getAxis( AxisType.X );
      xAxis.setLabel( "Points" );
      xAxis.setTickAngle( 0 );

      if( filteredStandings == null || filteredStandings.size() <= 0 ){
        horizontalBarModel[chMode] = new HorizontalBarChartModel();
        continue;
      }
      Collections.reverse( filteredStandings );
      ChartSeries series = new ChartSeries();
      //series.setLabel(  );
      for( Standings s : filteredStandings ) {
        String dataLabel
               = theModel.getUserFullName(
            s.getId().getUser() )
                 + " L" + s.getId().getLevel()
                 + "_C" + s.getId().getChampionship();
        switch( chMode ) {
          case ChMode.SRD:series.set( dataLabel, (int)( s.getPointsSd() + s.getPointsRd() ) );
            break;
          case ChMode.SD: series.set( dataLabel, (int)( s.getPointsSd() ) );
            break;
          case ChMode.RD: series.set( dataLabel, (int)( s.getPointsRd() ) );
            break;
          case ChMode.ED: series.set( dataLabel, (int)( s.getPointsEd() ) );
            break;
          case ChMode.SO: series.set( dataLabel, (int)( s.getPointsSo() ) );
            break;
          case ChMode.RO: series.set( dataLabel, (int)( s.getPointsRo() ) );
            break;
          case ChMode.EO: series.set( dataLabel, (int)( s.getPointsEo() ) );
            break;
        }
      }
      model.addSeries( series );
      Collections.reverse( filteredStandings );

      horizontalBarModel[chMode] = model;
    }
  }

  public int getChartHeight() {
    return 60 + 15 * ( filteredStandings == null ? standings.size() : filteredStandings.size() );
  }

  public HorizontalBarChartModel getChartModel( int chMode ) {
    return horizontalBarModel[chMode];
  }

  ////////////////////////////////////////////////////////
  // Functionality Methods
  ////////////////////////////////////////////////////////
  public String getUserName( long userNumber ) {
    return theModel.getUserFullName( userNumber );
  }

  public String getChampionshipName( Standings item ) {
    return item == null ? "Unknown"
           : theModel
        .getChampionshipName(
          item.getId()
            .getLevel(),
          item.getId()
            .getChampionship()
        );
  }

  public String getLevelName( int level ) {
    String[] levelName = {
      "Planet",
      "Intl. Region",
      "Country",
      "Nat. Region",
      "State",
      "Municipality",
      "Venue",
      "Variant"
    };
    return level + " " + levelName[ level ];

  }

  private static class ChMode {

    public static final int SRD = 0;
    public static final int SD = 1;
    public static final int RD = 2;
    public static final int ED = 3;
    public static final int SO = 4;
    public static final int RO = 5;
    public static final int EO = 6;

    public ChMode() {
    }
  }

  public String getChampionshipsStandingsTitle() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "CHAMPIONSHIPS STANDINGS" );
  }

  public String getRowTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "ROW" );
  }

  public String getYearTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "YEAR" );
  }

  public String getUserTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "USER" );
  }

  public String getLevelTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "LEVEL" );
  }

  public String getChampionshipTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "CHAMPIONSHIP" );
  }

  public String getSR_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "SR DRIVER POINTS" );
  }

  public String getS_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "S DRIVER POINTS" );
  }

  public String getR_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "R DRIVER POINTS" );
  }

  public String getE_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "E DRIVER POINTS" );
  }

  public String getS_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "S OWNER POINTS" );
  }

  public String getR_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "R OWNER POINTS" );
  }

  public String getE_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "E OWNER POINTS" );
  }

  public void sortEvent( SortEvent e ){
    e.getSortColumn();
  }

  public void filterEvent( FilterEvent e ){
    e.toString();
  }
}

我找到了导致这种奇怪行为的原因。

碰巧我正在使用filteredStandings 列表更新Horizo​​ntalBarChartModel 数组,但是,当该列表为空时,我在创建模型后保留了模型。 这似乎在某个地方留下了一个空指针的模型,因为它没有系列。 这个空指针以某种方式破坏了其他东西,非常奇怪的是,排序事件没有发送。

只是为了那些好奇的人,我把代码放在这里:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                template="/TemplateBasic.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui">

  <ui:define name="content">

    <table>
      <tr>
        <td><p:graphicImage url="#{resource['images/goldCup3small.jpg']}" height="30" /></td>
        <td><h2>#{listStandingsBean.getChampionshipsStandingsTitle()}</h2></td>
        <td><p:graphicImage url="#{resource['images/goldCup3small.jpg']}" height="30" /></td>
      </tr>
    </table>

    <p:dataTable id="standingsList"
                 var="item" 
                 value="#{listStandingsBean.standings}" 
                 widgetVar="standingsTable"
                 emptyMessage="#{mainBean.getListEmptyMsg()}" 
                 filteredValue="#{listStandingsBean.filteredStandings}"
                 style="white-space: pre-line; font-stretch: condensed; width: 100%; padding: 0px" 
                 scrollable="true"
                 scrollRows="20"
                 scrollHeight="250"
                 scrollWidth="90%"
                 liveScroll="false"
                 resizableColumns="true"
                 rowIndexVar="rowIndex"
                 >

      <f:facet name="header">
        <p:outputPanel>
          <h:outputText value="#{mainBean.getSearchAllFieldsLabel()}" />
          <p:inputText id="globalFilter" 
                       onkeyup="PF( 'standingsTable' ).filter()" 
                       style="width:150px" 
                       placeholder="#{mainBean.getEnterKeywordPlaceholder()}"/>

          <p:commandButton actionListener="#{listStandingsBean.clickReturn()}"
                           icon="fa fa-fw fa-arrow-left"
                           title="#{mainBean.getReturnButtonTitle()}"
                           onclick="PF('dlgWait').show();"
                           ajax="true"
                           style="float: left"/>

        </p:outputPanel>
      </f:facet>

      <p:column headerText="#{listStandingsBean.getRowTxt()}" 
                footerText="#{listStandingsBean.getRowTxt()}" 
                width="10" style="text-align: center">
        <h:outputText value="#{rowIndex+1}" />
      </p:column>

      <p:column filterBy="#{item.id.year}" 
                sortBy="#{item.id.year}" 
                headerText="#{listStandingsBean.getYearTxt()}" 
                footerText="#{listStandingsBean.getYearTxt()}" 
                filterMatchMode="exact" width="70" style="text-align: center; padding: 1px">
        <f:facet name="filter">
          <p:spinner size="3" value="#{listStandingsBean.currYear}"
                     onchange="PF( 'standingsTable' ).filter()"
                     styleClass="year-spinner" >
            <f:converter converterId="javax.faces.Integer" />
          </p:spinner>
        </f:facet>
        <h:outputText value="#{item.id.year}"/>
      </p:column>

      <p:column filterBy="#{listStandingsBean.getUserName( item.id.user )}"
                sortBy="#{listStandingsBean.getUserName( item.id.user )}"
                headerText="#{listStandingsBean.getUserTxt()}" 
                footerText="#{listStandingsBean.getUserTxt()}" 
                filterMatchMode="contains" width="120" style="white-space: pre-line; padding: 2px">
        <f:facet name="filter">  
          <p:inputText size="10" onkeyup="PF( 'standingsTable' ).filter()" /> 
        </f:facet>
        <h:outputText value="#{listStandingsBean.getUserName( item.id.user )}" />
      </p:column>

      <p:column filterBy="#{item.id.level}" 
                sortBy="#{item.id.level}" 
                headerText="#{listStandingsBean.getLevelTxt()}" 
                footerText="#{listStandingsBean.getLevelTxt()}" 
                filterMatchMode="contains" width="70" style="padding: 2px">
        <f:facet name="filter" >
          <p:selectOneMenu onchange="PF( 'standingsTable' ).filter()">
            <f:selectItem noSelectionOption="true"  />
            <f:selectItems value="#{listStandingsBean.levels}"  />
          </p:selectOneMenu>
        </f:facet>
        <h:outputText value="#{listStandingsBean.getLevelName( item.id.level )}" />
      </p:column>

      <p:column filterBy="#{listStandingsBean.getChampionshipName( item )}" 
                sortBy="#{listStandingsBean.getChampionshipName( item )}" 
                headerText="#{listStandingsBean.getChampionshipTxt()}" 
                footerText="#{listStandingsBean.getChampionshipTxt()}" 
                filterMatchMode="contains" width="130" style="white-space: pre-line; padding: 2px">
        <h:outputText value="#{listStandingsBean.getChampionshipName( item )}" />
      </p:column>

      <p:column sortBy="#{item.pointsSd+item.pointsRd}" 
                style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getSR_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getSR_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSd+item.pointsRd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsSd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getS_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getS_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSd}" />
      </p:column>

      <p:column sortBy="#{item.pointsRd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getR_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getR_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsRd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsEd}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getE_DriverPointsTxt()}" 
                footerText="#{listStandingsBean.getE_DriverPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsEd}"/>
      </p:column>

      <p:column sortBy="#{item.pointsSo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getS_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getS_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsSo}" />
      </p:column>

      <p:column sortBy="#{item.pointsRo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getR_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getR_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsRo}"/>
      </p:column>

      <p:column sortBy="#{item.pointsEo}" style="white-space: pre-line; text-align: right" 
                headerText="#{listStandingsBean.getE_OwnerPointsTxt()}" 
                footerText="#{listStandingsBean.getE_OwnerPointsTxt()}" width="60">
        <h:outputText value="#{item.pointsEo}"/>
      </p:column>

      <p:ajax event="filter" update="contentForm:graphsAccordion"
              listener="#{listStandingsBean.filterEvent}"/>
      <p:ajax event="sort" update="contentForm:graphsAccordion"
              listener="#{listStandingsBean.sortEvent}" />

    </p:dataTable>

    <p:remoteCommand name="onCompleteAuto" oncomplete="PF('standingsTable').filter()" autoRun="true" />

    <p:accordionPanel id="graphsAccordion" 
                      widgetVar="graphsAccordion"
                      multiple="true"
                      activeIndex="-1"
                      style="width:90%" >
      <p:tab title="#{listStandingsBean.getSR_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSRD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(0)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getS_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(1)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getR_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartRD"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(2)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getE_DriverPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartED"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(3)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getS_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartSO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(4)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getR_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartRO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(5)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>

      <p:tab title="#{listStandingsBean.getE_OwnerPointsTxt()}">
        <div align="left">
          <p:chart id="standingsChartEO"
                   type="bar" 
                   model="#{listStandingsBean.getChartModel(6)}" 
                   responsive="true"
                   style="height:#{listStandingsBean.chartHeight}px; width:80%; "
                   />
        </div>
      </p:tab>
    </p:accordionPanel>


  </ui:define>


</ui:composition>

支持豆:

@ManagedBean( name = "listStandingsBean" )
@ViewScoped
public class ListStandingsBean {

  @ManagedProperty( value = "#{mainBean}" )
  private MainBean mainBean;

  private ModelForView theModel;
  private Controller theController;

  private List<Standings> standings;
  private List<Standings> filteredStandings;
  private Long index = 0L;
  private HorizontalBarChartModel horizontalBarModel[];

  /**
   * Creates a new instance of StandingsBean
   */
  public ListStandingsBean() {
    horizontalBarModel = new HorizontalBarChartModel[ 7 ];
  }

  public MainBean getMainBean() {
    return mainBean;
  }

  public void setMainBean( MainBean mainBean ) {
    this.mainBean = mainBean;
  }

  @PostConstruct
  public void init() {
    theModel = mainBean.getModel();
    theController = mainBean.getController();
    index = 0L;
    standings = theModel.getStandings();
    horizontalBarModel = new HorizontalBarChartModel[7];
    updateCharts( standings );
  }

  //
  // queries
  //
  public Integer getCurrYear() {
    Calendar c = new GregorianCalendar();
    return c.get( Calendar.YEAR );
  }

  public void setCurrYear( Integer y ) {
  }

  public void setStandings( List<Standings> standings ) {
    this.standings = standings;
  }

  public List<Standings> getStandings() {
    return standings;
  }

  public Long getIndex() {
    return ++index;
  }

  public List<Byte> getLevels() {
    Byte levels[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
    return Arrays.asList( levels );
  }

  public List<Standings> getFilteredStandings() {
    index = 0L;
    return filteredStandings;
  }

  public void setFilteredStandings( List<Standings> filteredStandings ) {
    this.filteredStandings = filteredStandings;
    if( filteredStandings != null )
      this.updateCharts( filteredStandings );
  }

  /*
   * user actions
   */
  public void clickReturn() {
    theController.clickReturn( UI.LIST_STANDINGS );
  }

  public void updateCharts( List<Standings> theList ) {
    for( int chMode = 0; chMode < 7; chMode++ ) {

      HorizontalBarChartModel model = new HorizontalBarChartModel();
      model.setShadow( false );
      model.setZoom( false );
      model.setMouseoverHighlight( false );
//    model.setLegendCols( 4 );
      model.setAnimate( false );
      model.setMouseoverHighlight( true );
      model.setBarMargin( 0 );
      model.setBarPadding( 1 );
//    model.setLegendPlacement( LegendPlacement.OUTSIDE );
//    model.setExtender( "standingsChartExtender" );
//    model.setLegendPosition( "ne" );
      model.setShowPointLabels( true );
      model.setShowDatatip( false );
      model.getAxes()
        .put( AxisType.Y, new CategoryAxis( "Driver Level_Championship" ) );
      Axis xAxis = model.getAxis( AxisType.X );
      xAxis.setLabel( "Points" );
      xAxis.setTickAngle( 0 );

      Collections.reverse( theList );
      ChartSeries series = new ChartSeries();
      //series.setLabel(  );
      for( Standings s : theList ) {
        String dataLabel
               = theModel.getUserFullName(
            s.getId().getUser() )
                 + " L" + s.getId().getLevel()
                 + "_C" + s.getId().getChampionship();
        switch( chMode ) {
          case ChMode.SRD:series.set( dataLabel, (int)( s.getPointsSd() + s.getPointsRd() ) );
            break;
          case ChMode.SD: series.set( dataLabel, (int)( s.getPointsSd() ) );
            break;
          case ChMode.RD: series.set( dataLabel, (int)( s.getPointsRd() ) );
            break;
          case ChMode.ED: series.set( dataLabel, (int)( s.getPointsEd() ) );
            break;
          case ChMode.SO: series.set( dataLabel, (int)( s.getPointsSo() ) );
            break;
          case ChMode.RO: series.set( dataLabel, (int)( s.getPointsRo() ) );
            break;
          case ChMode.EO: series.set( dataLabel, (int)( s.getPointsEo() ) );
            break;
        }
      }
      if( theList != null && theList.size() > 0 )
        model.addSeries( series );
      Collections.reverse( theList );

      horizontalBarModel[chMode] = model;
    }
  }

  public int getChartHeight() {
    return 60 + 15 * ( filteredStandings == null ? standings.size() : filteredStandings.size() );
  }

  public HorizontalBarChartModel getChartModel( int chMode ) {
    return horizontalBarModel[chMode];
  }

  ////////////////////////////////////////////////////////
  // Functionality Methods
  ////////////////////////////////////////////////////////
  public String getUserName( long userNumber ) {
    return theModel.getUserFullName( userNumber );
  }

  public String getChampionshipName( Standings item ) {
    return item == null ? "Unknown"
           : theModel
        .getChampionshipName(
          item.getId()
            .getLevel(),
          item.getId()
            .getChampionship()
        );
  }

  public String getLevelName( int level ) {
    String[] levelName = {
      "Planet",
      "Intl. Region",
      "Country",
      "Nat. Region",
      "State",
      "Municipality",
      "Venue",
      "Variant"
    };
    return level + " " + levelName[ level ];

  }

  private static class ChMode {

    public static final int SRD = 0;
    public static final int SD = 1;
    public static final int RD = 2;
    public static final int ED = 3;
    public static final int SO = 4;
    public static final int RO = 5;
    public static final int EO = 6;

    public ChMode() {
    }
  }

  public String getChampionshipsStandingsTitle() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "CHAMPIONSHIPS STANDINGS" );
  }

  public String getRowTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "ROW" );
  }

  public String getYearTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "YEAR" );
  }

  public String getUserTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "USER" );
  }

  public String getLevelTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "LEVEL" );
  }

  public String getChampionshipTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "CHAMPIONSHIP" );
  }

  public String getSR_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "SR DRIVER POINTS" );
  }

  public String getS_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "S DRIVER POINTS" );
  }

  public String getR_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "R DRIVER POINTS" );
  }

  public String getE_DriverPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "E DRIVER POINTS" );
  }

  public String getS_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "S OWNER POINTS" );
  }

  public String getR_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "R OWNER POINTS" );
  }

  public String getE_OwnerPointsTxt() {
    return java.util.ResourceBundle.getBundle( "View/BundleViewSpanish" )
      .getString( "E OWNER POINTS" );
  }

  public void sortEvent( SortEvent e ){
    e.getSortColumn();
  }

  public void filterEvent( FilterEvent e ){
    e.toString();
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM