2011-05-03 164 views
0

命令按钮的onclick事件不起作用其不调用银行bean方法。还有一些其他CommandButton控件像无法执行Backing bean方法

action="#{editBean.editQuestionAction}" 
action="#{editBean.addNewQuestionAction}" 

中工作正常,但它不是在'行动=“#{} editBean.updateQuestionAction”的情况下

<p:tab title="Questions"> 
       <h:outputText value="Select a project to add questions: " /> 
       <h:selectOneMenu id="projects_dpd" value="#{editBean.currentProject.projectId}" onchange=""> 
        <f:selectItems value="#{projectBean.projects}" /> 
       </h:selectOneMenu><br/> 

       <h:form id="listForm"> 
        <p:panel id="listPanel" header="List of Questions" toggleable="false" closable="false"> 
         <p:dataList paginatorAlwaysVisible="false" paginatorPosition="bottom" effect="slide" 
            value="#{editBean.editBeanList}" var="q" 
            paginator="true" rows="5" effectSpeed="fast" 
            paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}" 
            rowsPerPageTemplate="5,10,15"> 

          <p:column> 
           <p:commandButton action="#{editBean.**editQuestionAction**}" update="editPanel" title="Edit Question" image="edit"> 
            <f:setPropertyActionListener value="#{q}" target="#{editBean.editQuestion}" /> 
           </p:commandButton> 
           <p:spacer width="30" height="30" /> 
           <h:outputText value="#{q.question.questionId} -> #{q.question.questionText} ->"/> <b><h:outputText value="#{q.question.questionType}" /></b> 
          </p:column> 
         </p:dataList> 
         <p:commandButton value="New Question !!" action="#{editBean.**addNewQuestionAction**}" update="editPanel" /> 
         <p:commandButton ajax="false" value="Home Page !!" action="#{indexBean.**gotoHomePage}**" /> 
        </p:panel> 
       </h:form> 

       <p:layoutUnit position="center" scrollable="true"> 
        <p:panel id="editPanel" header="Edit Section" toggleable="false" closable="false" > 
         <h:form id="form"> 
          <table cellspacing="20"> 
           <tr> 
            <td><h:outputLabel value="Question Text:" /></td> 
            <td><p:inputTextarea id="questionText" required="true" value="#{editBean.editQuestion.question.questionText}" autoResize="true" effectDuration="400" maxHeight="100" /></td>        <td><p:message for="questionText" /></td> 
           </tr> 

           <tr> 
            <td>Review:</td> 
            <td><p:inputTextarea id="reviewText" required="true" value="#{editBean.editQuestion.question.reviewText}" autoResize="true" effectDuration="400" maxHeight="100" /></td> 
            <td><p:message for="reviewText" /></td> 
           </tr> 

           <tr> 
            <td>Option Type:</td> 
            <td> 
             <h:selectOneRadio label="Option Type" value="#{editBean.editQuestion.question.optionType}"> 
              <f:selectItem itemLabel="Currency" itemValue="currency" /> 
              <f:selectItem itemLabel="Hours" itemValue="hours" /> 
             </h:selectOneRadio> 
            </td> 
           </tr> 

           <tr> 
            <td>Question Type:</td> 
            <td> 
             <h:selectOneRadio label="Question Type" value="#{editBean.editQuestion.question.questionType}"> 
              <f:selectItem itemLabel="Mandatory" itemValue="mandatory" /> 
              <f:selectItem itemLabel="Linked" itemValue="linked" /> 
             </h:selectOneRadio> 
            </td> 
           </tr> 

           <tr> 
            <td align="right"> 
             <h:selectBooleanCheckbox label="Hide Weight until Review !!" value="#{editBean.editQuestion.question.hideWeight}" /> 
            </td> 
            <td>Hide Weight Until Review</td> 
           </tr> 

           <tr> 
            <td>Options:</td> 
            <td> 
             <p:panel header="Add Option"> 
              <h:panelGrid columns="2" id="grid"> 
               <h:outputLabel value="Text : " for="txt_title"></h:outputLabel> 
               <p:inputText id="txt_title" 
                  value="#{editBean.placeHolderForOption.optionText}" /> 

               <h:outputLabel value="Weight : " for="txt_author"></h:outputLabel> 
               <p:inputText id="txt_author" 
                  value="#{editBean.placeHolderForOption.weight}" /> 

               <p:commandButton value="Reset" type="reset"/> 
               <p:commandButton value="Add" update="options @parent" 
                   action="#{editBean.initOption}" > 
                <p:collector value="#{editBean.placeHolderForOption}" 
                   addTo="#{editBean.editQuestion.options}" /> 
               </p:commandButton> 
              </h:panelGrid> 
             </p:panel> 

             <p:outputPanel id="options"> 
              <p:dataTable value="#{editBean.editQuestion.options}" var="opt"> 
               <p:column headerText="Text" style="width:150px"> 
                <p:cellEditor> 
                 <f:facet name="output"> 
                  <h:outputText value="#{opt.optionText}" /> 
                 </f:facet> 
                 <f:facet name="input"> 
                  <h:inputText value="#{opt.optionText}" /> 
                 </f:facet> 
                </p:cellEditor> 
               </p:column> 
               <p:column headerText="Weight" style="width:150px"> 
                <p:cellEditor> 
                 <f:facet name="output"> 
                  <h:outputText value="#{opt.weight}" /> 
                 </f:facet> 
                 <f:facet name="input"> 
                  <h:inputText value="#{opt.weight}" /> 
                 </f:facet> 
                </p:cellEditor> 
               </p:column> 
               <p:column headerText="Linked Question" style="width:150px"> 
                <p:cellEditor> 
                 <f:facet name="output"> 
                  <h:outputText value="#{opt.linkedQuestionId}" /> 
                 </f:facet> 
                 <f:facet name="input"> 
                  <h:selectOneMenu value="#{opt.linkedQuestionId}"> 
                   <f:selectItems value="#{editBean.linkedQuestionIds}" /> 
                  </h:selectOneMenu> 
                 </f:facet> 
                </p:cellEditor> 
               </p:column> 
               <p:column headerText="Display Order" style="width:150px"> 
                <p:cellEditor> 
                 <f:facet name="output"> 
                  <h:outputText value="#{opt.displayOrder}" /> 
                 </f:facet> 
                 <f:facet name="input"> 
                  <h:inputText value="#{opt.displayOrder}" /> 
                 </f:facet> 
                </p:cellEditor> 
               </p:column> 
               <p:column> 
                <f:facet name="header"> 
                 <h:outputText value="Operation" /> 
                </f:facet> 
                <p:commandLink value="Remove" update="form:options" process="@this"> 
                 <p:collector value="#{opt}" 
                    removeFrom="#{editBean.editQuestion.options}" /> 
                </p:commandLink> 
                <p:spacer width="10" /> 
                <p:rowEditor /> 
               </p:column> 
              </p:dataTable> 
             </p:outputPanel> 
            </td> 
           </tr> 
          </table> 
          <p:commandButton ajax="false" value="Update Question" action="#{editBean.updateQuestionAction}" 
              rendered="#{editBean.operation eq 'edit'}" /> 

          <p:commandButton ajax="false" value="Add Question" update="msgs listForm:listPanel" action="#{editBean.saveQuestion}" 
              rendered="#{editBean.operation eq 'add'}"> 
           <p:collector value="#{editBean.editQuestion}" 
              addTo="#{editBean.editBeanList}" /> 
          </p:commandButton> 

          <p:commandButton ajax="false" value="Delete Question" update="msgs listForm:listPanel" action="#{editBean.deleteQuestionAction}" 
              rendered="#{editBean.operation eq 'edit'}"> 
           <p:collector value="#{editBean.editQuestion}" 
              removeFrom="#{editBean.editBeanList}" /> 
          </p:commandButton> 
         </h:form> 
        </p:panel> 
       </p:layoutUnit> 
      </p:tab> 

它没有得到当我点击链接执行

@ManagedBean 
    @RequestScoped 
    public class EditBean { 

     @ManagedProperty(value = "#{questionDao}") 
     private QuestionDao questionDao; 
     private String operation; 
     private QuestionHelper editQuestion; 
     private SelectItem[] linkedQuestionIds; 
     private List<QuestionHelper> linkedQuestions = new ArrayList<QuestionHelper>(); 
     private List<QuestionHelper> allQuestions = new ArrayList<QuestionHelper>(); 
public void editQuestionAction() { 
     operation = "edit"; 
    } 

    public void deleteQuestionAction() { 
     questionDao.delete(editQuestion.getQuestion()); 
     listBean.getListOfQuestions().remove(editQuestion); 
     addNewQuestionAction(); 
     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Deleted !")); 
    } 

    public void updateQuestionAction() { 
     editQuestion.getQuestion().getOptionses().clear(); 
     for (Options o : editQuestion.getOptions()) { 
      o.setQuestions(editQuestion.getQuestion()); 
      editQuestion.getQuestion().getOptionses().add(o); 
     } 
     getQuestionDao().update(editQuestion.getQuestion()); 
     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Updated !")); 
    } 
+0

显示bean定义 – Bozho 2011-05-03 10:11:44

+0

它是一个非常大的文件我不能在这里包括 – Maddy 2011-05-03 10:20:15

+1

@madhav整个文件可能是大的,但你可以提取相关的位 – Bozho 2011-05-03 10:23:56

回答

1

您好我找到答案了我的问题,该命令按钮不工作,因为管理bean的渲染标签和请求范围,因为在每一个后续请求后压命令按钮我的请求scoped(iseditable)正在重置。当我做到这一点时,Session的工作范围很好。