2013-09-22 86 views
1

我使用primefaces DataList控件,它包含了與它綁定列表,, DataList控件包含單選按鈕,我想改變這種綁定列表/更新值我想這代碼,但它不工作更新Datalist中值

<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類包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()); 
     } 

    } 

} 

我想在列表中更新。請幫我

回答

3

使用Ajax上p:selectOneRadio提交每次用戶選擇一個答案,答案的答案值。

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

我不想更新任何組件我只想要arraylist進行更改 –

+0

然後刪除更新屬性。 會爲您完成這項工作。 –

+0

其不工作仍然答案值爲0 –