简体   繁体   English

更新素数中的数据列表值

[英]Update Datalist value in primefaces

i am using primefaces datalist , it contains list binded with it ,, datalist contains radio button i want to change / update values of that binded list i tried this code but its not working 我正在使用primefaces数据列表,它包含与其绑定的列表,数据列表包含单选按钮,我想更改/更新该绑定列表的值,但我尝试了此代码,但无法正常工作

<p:dataList var="question" value="#{formTableBean.question}"
                    type="definition" >
                    <h:outputText value="#{question.text}"
                        style="font-size:14px;font-weight:bold" />

                    <h:panelGrid columns="2" width="100%" style="margin-bottom:10px"
                        cellpadding="10">

                        <h:outputText value="Options: " />
                        <p:selectOneRadio id="options" value="#{question.answer}" >
                            <f:selectItem itemLabel="Strongly Agree" itemValue="1" />
                            <f:selectItem style="margin-right:20px" itemLabel="Agree"
                                itemValue="2" />
                            <f:selectItem style="margin-right:20px" itemLabel="Disagree"
                                itemValue="3" />
                            <f:selectItem itemLabel="Strongly Disagree" itemValue="4" />
                            <p:spacer width="100"></p:spacer>
                        </p:selectOneRadio>
                    </h:panelGrid>
                </p:dataList>

bean class package Bean; bean类包Bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;

import DAO.Dao;
import DTO.FormDTO;
import DTO.QuestionDTO;

@ManagedBean
@ViewScoped
public class FormTableBean {

    FormDTO selectedForm;
    List<QuestionDTO> question;

    public List<QuestionDTO> getQuestion() {
        return question;
    }

    public void setQuestion(List<QuestionDTO> question) {
        this.question = question;
    }

    public FormDTO getSelectedForm() {
        return selectedForm;
    }

    public void setSelectedForm(FormDTO selectedForm) {
        this.selectedForm = selectedForm;
    }

    boolean renderFormPanal = false;

    public boolean getRenderFormPanal() {
        return renderFormPanal;
    }

    public void setRenderFormPanal(boolean renderFormPanal) {
        this.renderFormPanal = renderFormPanal;
    }

    List<FormDTO> formList;

    public List<FormDTO> getFormList() {
        return formList;
    }

    public void setFormList(List<FormDTO> formList) {
        this.formList = formList;
    }

    Dao daoclass = new Dao();

    public FormTableBean() {

        User u = getCurrentUser();
        String email = u.getEmailAddress();
        int eid = daoclass.emailToEid(email);
        formList = new ArrayList<FormDTO>();
        formList = daoclass.getAllForm(eid);

    }

    protected User getCurrentUser() {
        User u = null;
        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext externalContext = fc.getExternalContext();
        Long id = Long.parseLong(externalContext.getUserPrincipal().getName());
        try {
            u = UserLocalServiceUtil.getUserById(id);
        } catch (com.liferay.portal.kernel.exception.PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (com.liferay.portal.kernel.exception.SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return u;
    }

    public void showForm() {
        question = new ArrayList<QuestionDTO>();
        setRenderFormPanal(true);
        int formid = selectedForm.getFid();
        question = daoclass.getQuestion(formid);

    }

    public void saveForm() {
        for (int i = 0; i < question.size(); i++) {
            System.out.print("QID:"+question.get(i).getAnswer());
        }

    }

}

i want to get answers value updated in list .please help me 我想获取列表中更新的答案值。请帮助我

Use Ajax on p:selectOneRadio to submit the answer every time user selects an answer. 每次用户选择答案时,在p:selectOneRadio上使用Ajax提交答案。

<p:selectOneRadio id="options" value="#{question.answer}" >
   <p:ajax event="valueChange" update="any_component's_id_you_want_to_update" />
   ....
   ....
</p:selectOneRadio>

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

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