PrimeFaces获取数据表的所有行值

时间:2013-05-23 05:48:45

标签: jsf primefaces datatable row

我是初脸的新人。我在dataTable上有一个复选框和文本框值.DataTable将从数据库加载数据。请参阅下面的代码

text.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
<ui:composition template="../templates/layout.xhtml">
  <ui:define name="metadata">
    <f:metadata>
      <f:event type="preRenderView" listener="#{kooBean.initEdit}" />
    </f:metadata>
  </ui:define>
  <ui:define name="content">
    <h:form prependId="false" id="growlForm">
      <p:growl id="growl" showDetail="#{applicationBean.isShowDetailMessage()}" />
    </h:form>



    <h:form id="form">  

    <p:dataTable id="list" value="#{kooBean.model}" lazy="true" var="kooTable" 
    rendered="#{kooBean.dataVisible}"  paginatorTemplate=" {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
    rowsPerPageTemplate="5,10,25,50" rows="10" sortBy="#{kooTable.id}"  selection="#{kooBean.selectedCars}"
    rowKey=" #{kooTable.id}">


       <f:facet name="header">
            Checkbox Based Selection
        </f:facet>

            <p:column selectionMode="multiple"  style="width:10%;text-align:center" />
            <p:column headerText="Description" >
                #{kooTable.description}
                <p:inputText value=" #{kooTable.param_str}" />
            </p:column>

            <f:facet name="footer">  
            <p:commandButton id="multiViewButton" value="View" icon="ui-icon-search"  
             update=":form:displayMulti" oncomplete="multiCarDialog.show()"/>  
          </f:facet>  


         </p:dataTable>

    </h:form>


  </ui:define>
</ui:composition>
</html>

bean.java

    package my.com.mesiniaga.sphere.web;

import static my.com.mesiniaga.sphere.domain.KooPredicate.nameLike;
import my.com.mesiniaga.sphere.domain.KooTable;
import java.util.Date;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.model.LazyDataModel;
import org.springframework.roo.addon.jsf.managedbean.RooJsfManagedBean;
import org.springframework.roo.addon.serializable.RooSerializable;

import my.com.mesiniaga.sphere.service.KooService;
import my.com.mesiniaga.sphere.service.QueryDslSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


import java.util.Date;

import com.mysema.query.types.Predicate;



@RooSerializable
@RooJsfManagedBean(entity = KooTable.class, beanName = "kooBean")
public class KooBean {

    private KooTable kooTable = new KooTable();



    private String attribute;
    private List<String> cols;
    public String userId;
    public String emailNotification;
    private boolean addGroup = false;
    private boolean editGroup = false;
    private boolean addGroupUser = false;

    private KooTable selectedCar;  
    private KooTable[] selectedCars;  


    private final LazyDataModel<KooTable> model = new AbstractQueryDslJpaLazyDataModel<KooTable>() {

        @Override
        public Predicate getPredicate(){
//          LOG.info(getKooTable().getName());
            return nameLike(getKooTable().getDescription());

        }
//      
        @Override
        public QueryDslSupport<KooTable> getQueryDslSupport(){
            return kooService;
        }
    };

    public LazyDataModel<KooTable> getModel() {
        return model;
    }

    public String getUserId() {
        return userId;
    }
//
//  public void setUserId(String userId) {
//      this.userId = userId;
//  }

    public String getEmailNotification() {
        return emailNotification;
    }
//
//  public void setEmailNotification(String emailNotification) {
//      this.emailNotification = emailNotification;
//  }

    public List<String> getCols() {
        return cols;
    }

    public void setCols(List<String> cols) {
        this.cols = cols;
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }


    public boolean isAddGroup() {
        return addGroup;
    }

    public void setAddGroup(boolean addGroup) {
        this.addGroup = addGroup;
    }

    public boolean isEditGroup() {
        return editGroup;
    }

    public void setEditGroup(boolean editGroup) {
        this.editGroup = editGroup;
    }

    public boolean isAddGroupUser() {
        return addGroupUser;
    }

    public void setAddGroupUser(boolean addGroupUser) {
        this.addGroupUser = addGroupUser;
    }

    public void initCreatePage() {
        //Initialize user group listing page

        cols = new ArrayList<String>();
        cols.add("id");
        cols.add("description");

//      displayGroupsList();

        if (!FacesContext.getCurrentInstance().isPostback()) {
//          if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("edit") != null) {
//              LOG.info("EDIT....");
//              attribute = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer");
//              initEdit();
//              editGroup = true;
//          } else if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("create") != null) {
//              LOG.info("CREATE....");
//              addGroup = true;
//          }
        }
    }

//      
//  public String displayGroupsList() {
//      findAllGroupses();
//      return LIST_NAVIGATION_PAGE;
//  }
//  
//  public String cancelCreateGroup(){
//      return LIST_NAVIGATION_PAGE;
//  }
//  
//  public String createGroup() {
//      String message = "";
//      try {
//
//          if (groups.getId() != null) {
//              //submit response inquiry
//              
//              groupsService.responseInquiry(groups);
//              message = "message_successfully_updated";
//          } else {
//              groups.setDescription("none");
//              groups.setUpdatedby(1L);
//              groups.setUpdatedon(new Date());
//              groupsService.create(groups);
//              message = "message_successfully_created";
//          }
//      } catch (NestedRuntimeException e) {
//          LOG.error(e.getMostSpecificCause().getMessage(), e);
//          message = "Failed to update";
//          FacesMessage facesMessage = new FacesMessage(message);
//          facesMessage.setDetail(e.getMostSpecificCause()
//                  .getLocalizedMessage());
//          FacesContext.getCurrentInstance().addMessage(null, facesMessage);
//          return null;
//      }
//      FacesMessage facesMessage = MessageFactory.getMessage(message,
//              "groups");
//      FacesContext.getCurrentInstance().addMessage(null, facesMessage);
//      //      FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
////        reset();
//      return LIST_NAVIGATION_PAGE;
//  }

    public void initEdit() {

        System.out.println("init edit !");
//      String groupId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("groupId");
//      if (groupId != null) {
//          addGroupUser = true;
//          groupsWithTask = groupsService.findGroupsWithTask(Long.valueOf(groupId));
//          groups = groupsWithTask.getGroups();
//          if (groupsWithTask.getTask() != null) {
//              LOG.info("task name = " + groupsWithTask.getTask().getName());
//          }
//      } 
    }


    public boolean isDataVisible() {
        return true;
    }


//    public Car[] getSelectedCars() {  
//        return selectedCars;  
//    }  
//    public void setSelectedCars(Car[] selectedCars) {  
//        this.selectedCars = selectedCars;  
//    }  


     public KooTable[] getSelectedCars() {  
            return selectedCars;  
        }  
        public void setSelectedCars(KooTable[] selectedCars) {  
            this.selectedCars = selectedCars;  
        }  

        public KooTable getSelectedCar() {  
            return selectedCar;  
        }  

        public void setSelectedCar(KooTable selectedCar) {  
            this.selectedCar = selectedCar;  
        }  
}

这是我的问题。当我点击查看按钮时,我需要获取包含复选框值的每一行值,无论是复选框还是nt然后更新到数据库。有可能吗?

0 个答案:

没有答案