命令按钮onclick事件无效,不调用Banking bean方法。还有一些其他的commandButtons,比如
action="#{editBean.editQuestionAction}"
action="#{editBean.addNewQuestionAction}"
工作正常,但不是'action =“#{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 :(得分:1)
您好我找到了我的问题的答案,命令按钮因为渲染标记和托管bean的请求范围而无法正常工作,因为在按下命令按钮后的每个后续请求中,我的请求作用域(iseditable)正在重置。当我把它作为会议范围时,其工作正常。