大家,
我面临着一些棘手的问题,希望可以帮助你。提前谢谢。
我有一个表单,它有一个SelectOneMenu,用于填充列表供用户选择。之后,我根据SelectOneMenu中的用户选择从db加载详细信息,然后通过h:commandButton
保存到DB然而,h:commandButton中的动作(方法emailTemplateBean.updateTemplate)根本就没有被触发。下面是我的xhtml代码:
<f:metadata>
<f:event type="preRenderView" listener="#{emailTemplateBean.loadEmailTemplate}" />
</f:metadata>
<h:form id="update_template_form">
Template:
<h:selectOneMenu id="templateSelect" value="#{emailTemplateBean.selectedTemplateID}">
<f:selectItem id="templ0" itemLabel="" itemValue="" />
<f:selectItems value="#{emailTemplateBean.emailTemplateList}" var="t" itemLabel="#{t.templateName}" itemValue="#{t.templateID}" />
<f:ajax listener="#{emailTemplateBean.loadTemplateDetail}" execute="@this" render="@form" update="update_template_form" />
</h:selectOneMenu>
<table class="table table-bordered table-striped">
<tr>
<td>Subject (Eng):</td>
<td colspan="3"><h:inputText id="subject_en" value="#{emailTemplateBean.emailTemplate.subjectEN}"/></td>
</tr>
...
</table>
<h:commandButton styleClass="btn btn-small btn-primary" value="Update" action="#{emailTemplateBean.updateTemplate}"></h:commandButton>
</h:form>
支持bean:
@ManagedBean(name="emailTemplateBean")
@ViewScoped
public class EmailTemplateBean implements Serializable {
public void loadEmailTemplate(){
SchoolAdminBean schoolAdminBean = SystemUtilBean.findBean("schoolAdminBean");
schoolUser = schoolAdminBean.getLoginnedSchoolUser() ;
try{
emailTemplateList = EmailTemplateDAO.getAllTemplate(schoolUser.getSchool().getSchoolID());
}catch (Exception e){
logger.error(e);
}
}
public void loadTemplateDetail(){
logger.debug("loadTemplateDetail :" +selectedTemplateID);
try{
emailTemplate = EmailTemplateDAO.getEmailTemplate(selectedTemplateID, schoolUser.getSchool().getSchoolID());
logger.debug("subjectEN="+emailTemplate.getSubjectEN());
}catch (Exception e){
logger.error(e);
}
}
public String updateTemplate(){
logger.info("updateTemplate");
try{
EmailTemplateDAO.update(emailTemplate, schoolUser);
}catch (Exception e){
logger.error(e);
}
return "schoolInfo";
}
再次感谢......