0

我有一个应用程序从支持 bean 加载数据表。SubAreas数据表加载了正确的行数,但是它们在图像上是空的。调试后,我可以看到后备 bean 上的listaArea属性(负责填充表)正在从数据库中获取正确的数据。面积是实体。

空数据表

同一屏幕上的另一个名为Membros的数据表可以正常工作。

功能数据表

区域.XHTML

  <div>
    <fieldset style="display:#{(areaMB.state == 'update')?'block':'none'}">
      <p:dataTable var="teste" id="dtTeste" value="#{areaMB.listaArea}" 
                   widgetVar="dtArea" paginator="true" 
                   paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                   rowsPerPageTemplate="20, 50, 100"
                   rows="20" rowKey="#{area.idArea}" 
                   emptyMessage="Nenhum registro" paginatorPosition="bottom">

        <p:column headerText="#" width="10%">
          <h:outputText value="#{area.idArea}" />
        </p:column>

        <p:column headerText="Descrição" width="40%" 
                  filterBy="#{area.descricao}" 
                  filterMatchMode="contains">
          <h:outputText value="#{area.descricao}" />
        </p:column>

        <p:column headerText="Sigla" width="20%">
          <h:outputText value="#{area.sigla}" />
        </p:column>

        <p:column headerText="Ativo" width="20%">
          <h:outputText value="ATIVO" rendered="#{area.flgAtivo==1}" />
          <h:outputText value="INATIVO" rendered="#{area.flgAtivo==0}" />
        </p:column>

        <p:column headerText="" width="10%" style="text-align:center">
          <p:commandButton action="#{areaMB.preparaAlterar}" 
                           update=":formu" 
                           icon="fa fa-pencil" style="margin-right:10px" 
                           title="Alterar" 
                           styleClass="btn btn-default btn-xs">
            <f:setPropertyActionListener target="#{areaMB.area}" value="#{area}" />
          </p:commandButton>
        </p:column>
      </p:dataTable>

    </fieldset>
  </div>
</h:panelGroup>

豆类

@Named
@ViewScoped
public class AreaMB implements Serializable {

    private String state = "search";
    private String descricao;
    private Area area = new Area();
    private Area subArea = new Area();
    private Usuario usuario = new Usuario();
    private AreaUsuario areaUsuario = new AreaUsuario();
    private List<Usuario> listaUsuario;
    private List<Area> listaArea;
    private List<AreaUsuario> listaAreaUsuario;
    private List<SelectItem> listaMembro;
    private List<Area> listaSubAreas;
    private List<TipoArea> listaTipoArea;
    private List<Area> listaAreaVinculada;

    @PostConstruct
    public void init() throws Exception {
        pesquisar();

    }

public void pesquisar() {
        try {
            listaArea = AreaService.getInstancia().pesquisar(area, 0, 0);
            listaTipoArea = TipoAreaService.getInstancia().getAll();

            //a area vinculada nao pode ser ela mesma
            listaAreaVinculada = AreaService.getInstancia().getAll();
            if (listaAreaVinculada.contains(area)) {
                listaAreaVinculada.remove(area);  
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

public void preparaAlterar() {
    try {
        state = "update";

        AreaUsuario au = new AreaUsuario();
        au.setIdArea(area.getIdArea());

        listaAreaUsuario = AreaUsuarioService.getInstancia().pesquisar(au, AreaUsuarioService.JOIN_USUARIO, 0);
        listaMembro = new ArrayList<SelectItem>();
        for (AreaUsuario aUsuario : listaAreaUsuario) {
            listaMembro.add(new SelectItem(aUsuario.getIdUsuario(), aUsuario.getUsuario().getNome()));
        }

        listaAreaVinculada.remove(area);  
        listaSubAreas = AreaService.getInstancia().getSubAreas(area);

    } catch (Exception e) {
        System.out.println(e.getStackTrace());
    }

}

为什么它会带来空单元格?

4

1 回答 1

1

您的 dateTable 的 var 称为 teste ( var="teste"),而在 values 中使用并在您的h:outputTextare 中呈现的 var area

您可以更改为var="area",或更改所有值并呈现h:outputText"#{teste.XXX}"

于 2018-09-26T15:26:04.457 回答