如何在数据表行primefaces Jsf中添加所有值

时间:2014-04-17 00:14:01

标签: jsf jsf-2 primefaces datatable

我有一个数据表:

            <p:dataTable id="marksTable"
                         var="item"
                         value="#{markingBean.markToEdit}"    
                         rowKey="#{markingBean.markToEdit}" 
                         paginator="true" rows="10"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                         rowsPerPageTemplate="5,10,15"
                         scrollable="true" 
                         liveScroll="true"
                         scrollRows="20"  
                         emptyMessage="No details was found with given criteria">
                <p:column headerText="#{bundle.labelMarkSectionOne} ">
                    <h:outputText value="#{item.markSectionOne}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionTwo}">
                    <h:outputText value="#{item.markSectionTwo}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionThree}">
                    <h:outputText value="#{item.markSectionThree}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionFour}">
                    <h:outputText value="#{item.markSectionFour}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionFive}">
                    <h:outputText value="#{item.markSectionFive}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionSix}">
                    <h:outputText value="#{item.markSectionSix}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionSeven}">
                    <h:outputText value="#{item.markSectionSeven}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionEight}">
                    <h:outputText value="#{item.markSectionEight}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionNine}">
                    <h:outputText value="#{item.markSectionNine}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionTen}">
                    <h:outputText value="#{item.markSectionTen}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionEleven}">
                    <h:outputText value="#{item.markSectionEleven}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionTwelve}">
                    <h:outputText value="#{item.markSectionTwelve}" />  
                </p:column>
                <p:column headerText="#{bundle.labelMarkSectionThirteen}">
                    <h:outputText value="#{item.markSectionThirteen}" />  
                </p:column>
            </p:dataTable>

这只会显示一行,我想要做的只是将所有这些值相加然后取平均值

我怎么能做到最好?

EDIT 作为要求

从存储所有值的数据库中重新获取数据,在数据表中它只显示数据表中一行之前预先选择的一行

这是标记bean

@Named(value = "markingBean")
@ViewScoped
//@RequestScoped
public class MarkingController {

    private String searchString;
    private String ordering;
    private String criteria;
    private String match;
    private Date today;
    private String caseMatch;
    private Boolean changed;
    //private Marking markSectionOne;
    // private Marking studentNumber;
    // private Marking markSectionTwo;
    //  private Marking markToEdit;
    private int spinnerField;
    private Marking markToCreate, markToEdit;
    private String searchMark;
    private List<Marking> userSearchResults;
    private List<Marking> marksList;
    private Person user;
    private Progress progress;
    private Marking marking;
    private Boolean isCompleted;
    private String disabled;
    private boolean value1;
    private boolean value2;
    private List<String> selectedOptions;
    private Integer option;
    private Integer number;
    private List<Marking> totalMark;

    @Inject
    PersonFacade personFacade;

    @Inject
    CohortFacade cohortFacade;

    @Inject
    MilestoneFacade milestoneFacade;

    @Inject
    ProjectFacade projectFacade;

    @Inject
    ProgressFacade progressFacade;

    @Inject
    MilestoneService milestoneService;

    @Inject
    MarkingFacade markingFacade;

    @Inject
    MarkingService markingService;

    @PostConstruct
    public void init() {
        this.markToCreate = new Marking();
        this.marking = new Marking();
        this.marksList = markingFacade.findAll();
        // totalMark = mark.list();
        changed = false; //required otherwise will work opposite of how we  want

        String username = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();

        // Get the logged in user
        List<Person> usernameSearchResults = this.personFacade.usernameSearch(FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName());
        if (usernameSearchResults.size() > 0) {
            this.user = usernameSearchResults.get(0);
        }

        String marking_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("edit_id");
        System.out.println(marking_id);
        if (marking_id != null) {
            this.markToEdit = this.markingFacade.find(Long.parseLong(marking_id));
        }

    }

    public void createMarkingOne() {
        System.out.println("in Create mark one");
        this.markingService.createMarking(this.markToCreate);
        //  this.markingFacade.create(this.markToCreate);
        this.setMessage(" saved");
    }

    public void createMarking() {
        System.out.println("in Create mark");
        this.markingService.createMarking(this.markToCreate);
        //  this.markingFacade.create(this.markToCreate);
        this.setMessage(" saved");
    }

    private void setMessage(String message) {
        FacesContext fc = FacesContext.getCurrentInstance();
        fc.addMessage(null, new FacesMessage(message, ""));
    }

    /* Delete mark*/
    public void deleteMark(Marking markToDelete) {
        /*  this.markingService.deleteMark(markToDelete);
         listMarks(); //need to add the list marks function
         this.setMessage("Mark has been deleted.");*/
        //this.markingFacade.remove(this.marking_id);
    }

    // Edit existing marks
    public void editMark() throws IOException {
        System.out.println("in edit mark");
        this.markingFacade.edit(this.markToEdit);
        this.setMessage("Mark(s) for the project has been successfully been recorded.");
        MarkingLog loadProp = new MarkingLog(); // re anable for testing when finished
        loadProp.loadProp();
    }

    public void addMessage(boolean markingCompleted) {
        String summary = markingCompleted ? "Checked" : "Unchecked";
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(summary));
    }

    public void editChange() {
        changed = true;
    }

    /**
     * SEARCHES *
     */
    //for the advanced search query
    public void basicMarkingSearch() {
        userSearchResults = markingFacade.basicMarkingSearch(searchString, criteria, ordering, match);
    }

    public void testMarkingSearch() {
        userSearchResults = markingFacade.testMarkingSearch(searchString, ordering, match);
    }

标记实体

@Entity(name = "MARKING")
public class Marking implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne
    private Person marker;

    @ManyToOne
    private Project project;

    // @ManyToOne
    //  private Project project;
    //@ManyToMany(mappedBy = "title")
    //private Project projectBeMarked;
    private String markingCompleted, markSectionOne, markSectionTwo, markSectionThree, markSectionFour,
            markSectionFive, markSectionSix, markSectionSeven, markSectionEight,
            markSectionNine, markSectionTen, markSectionEleven, markSectionTwelve, markSectionThirteen, markAdjust, overalMark, thirdMarker, plagorism;

我想要做的是将一行markSectionOne加到十三,然后取平均值并将其显示给用户

0 个答案:

没有答案