我正在尝试实现 ap:dialog。里面有一个选择列表。根据所选项目,我需要更新对话框上的模板。这工作正常。但是如果我<p:commandButton>
在动态呈现的模板中有一个,那么它的 actionListener 永远不会被触发。
示例:view.xhtml
<p:dialog modal="true" id="addSocialMediaAddressDialogPanel" widgetVar="addSocialMediaAddressDialog" width="500" >
<h:form id="addSocialMediaAddressForm">
<h:messages />
<p:selectOneMenu id="currentAddingSocialMedia" value="#{requestScope.selectedMedia}" >
<f:selectItems value="#{WebResource.getListByName('SOCIAL_MEDIAS')}" />
<p:ajax update="addSocialMediaAddressContentPanel" process="@this" />
</p:selectOneMenu>
<p:outputPanel id="addSocialMediaAddressContentPanel">
<ui:include src="#{contactBean.resolveTemplate(requestScope.selectedMedia)}"/>
</p:outputPanel>
</h:form>
</p:dialog>
我有这样的模板
templates
|_ twitter.xhtml
|_ facebook.xhtml
|_ googlePlus.xhtml
推特.xhtml
<table>
<tr>
<td>
<h:outputLabel styleClass="standardText" value="Twitter Screen Name"/>
</td>
<td>
<p:inputText id="twitterScreenName" value="#{requestScope.twitterScreenName}"/>
</td>
</tr>
<tr>
<td>
<p:commandButton value="Add Account" actionListener="#{contactBean.addTwitterAccount(requestScope.twitterScreenName)}" styleClass="btn-blue" process="@form" update=":growl, :messageForm"/>
</td>
</tr>
</table>
这是支持豆
@Component
@Scope("session")
public class ContactBean implements Serializable {
private static String SOCIAL_MEDIA_ACCOUNTS_TEMPLATE_PARENT_DIRECTORY = "/templates/";
public void addTwitterAccount(String screenName){
//this contiains the implmentation
}
public String resolveTemplate(String socialMedia){
if(socialMedia.equalsIgnoreCase("Twitter")){
return SOCIAL_MEDIA_ACCOUNTS_TEMPLATE_PARENT_DIRECTORY + "twitter.xhtml";
}
if(socialMedia.equalsIgnoreCase("Facebook")){
return SOCIAL_MEDIA_ACCOUNTS_TEMPLATE_PARENT_DIRECTORY + "facebook.xhtml";
}
else if(socialMedia.equalsIgnoreCase("Google+")){
return SOCIAL_MEDIA_ACCOUNTS_TEMPLATE_PARENT_DIRECTORY + "googlePlus.xhtml";
}
return "";
}
}
在这种情况下,我无法触发任何 actionListener,它是模板目录下任何模板的一部分。我正在使用 JSF 2.1.7 和 Primefaces 3.3。