【发布时间】:2014-12-13 21:04:10
【问题描述】:
我使用的是 PF 5.0 和 jsf 2.2.8,下面有代码。
<ui:composition template="/template/mastertemplate.xhtml">
<ui:define name="content">
<f:view>
<h:body>
<h:form id="bcr_form_2" styleClass="form">
<p:tabView id="bcrId_tabview">
<p:tab title="Budget Cash Demands">
<h:panelGrid>
<p:commandButton value="save" id="saveDemandId_cmdbutton"
action="#{budgetControlRegisterAction.saveNewDemand()}"
binding="#{budgetControlRegisterAction.myMessageCId}"
update=":#{p:component('saveId_message')}">
</p:commandButton>
<p:message id="saveId_message" for="saveDemandId_cmdbutton" ></p:message>
</h:panelGrid>
</h:form >
<!-- and all closing tags-->
BudgetControlRegisterAction.java 类 (@ResquestScoped)
private UIComponent myMessageCId;
// setter and getter
public String saveNewDemand() {
FacesContext context = FacesContext.getCurrentInstance();
log.info("client Id :" + myMessageCId.getClientId(context));
//log output is -----> client Id :bcr_form_2:bcrId_tabview:saveDemandId_cmdbutton
//id on browser is ------> bcr_form_2:bcrId_tabview:saveDemandId_cmdbutton
/*this is not working */
//when i use myMessageCId.getClientId(context) nothing displayed on client side
FacesContext.getCurrentInstance().addMessage(myMessageCId.getClientId(context),new FacesMessage(FacesMessage.SEVERITY_INFO, "some msg" , "some msg"));
/*this is working and displaying msg to client browser*/
// but when i put hard coded component client Id (copied from web browser) e.g bcr_form_2:bcrId_tabview:saveDemandId_cmdbutton
// see it is without leading colon (:)
// and myMessageCId.getClientId(context) gives me id with colon(:) see log output in above lines
FacesContext.getCurrentInstance().addMessage("bcr_form_2:bcrId_tabview:saveDemandId_cmdbutton",new FacesMessage(FacesMessage.SEVERITY_INFO, "some msg" , "some msg"));
}
如何通过 myMessageCId.getClientId(context) 方法获取客户端 ID(不带冒号)?
【问题讨论】:
标签: jsf-2 primefaces jsf-2.2