I'm trying to show a message when a autocomplete selection is made. It shows the message, but when i try to use the autocomplete again it doesn't execute my completeMethod.
View:
<p:messages id="gNewDiagnostic" for="guau" escape="false"/>
<p:panelGrid columns="2" styleClass="panelGridForm">
<p:outputLabel value="Patología:" for="pathologyND"/>
<p:autoComplete id="pathologyND" value="#{newDiagnostic.pathology}" completeMethod="#{newDiagnostic.completeTextPathology}">
<p:ajax event="blur" listener ="#{newDiagnostic.warningGest}"/>
</p:autoComplete>
<p:outputLabel value="Estado del Diagnóstico:" for="stateDiagnosticND" />
<p:selectOneMenu id="stateDiagnosticND" value="#{newDiagnostic.stateDiagnostic}">
<p:ajax update="gNewDiagnostic" listener="#{newDiagnostic.warningGest}">
</p:ajax>
<f:selectItem itemLabel="Seleccione un Item" itemValue="" />
<f:selectItem itemLabel="Sospecha" itemValue="sospecha" />
<f:selectItem itemLabel="Confirmado" itemValue="confirmado" />
</p:selectOneMenu>
</p:panelGrid>
Managed Bean:
public void warningGest() {
boolean type = diseasesFacade.diseaseType(pathology);
stateGes = true;
if (type == true && stateDiagnostic.equals("confirmado")) {
FacesContext.getCurrentInstance().addMessage("guau", new FacesMessage(FacesMessage.SEVERITY_WARN, "Advertencia", "La patología " + pathology + " es una enfermedad GES. "));
stateGes = false;
}
}
Solved.
The problem was in a growl nested in the parent form. The growl missed some attributes and had the property autoUpdate=true causing failure in all ajax processing after a message was added to the context.
Deleting the growl fixed the issue.
Related
I'm trying get a value from a p:inputText is inside a p:dialog but this is returning null to my bean.
The inputText motivoCancelamento needs to be filled with the content of my inputText motivoCancelamentoDialog inside the dialog.
The another ones are ok, like status, protocoloCancelamento and dataCancelamento.
Can anyone help me?
<h:form id="form">
<p:toolbar>
<f:facet name="left">
<p:growl id="messages" showDetail="true"/>
<p:dialog header="Cancelar Nota" widgetVar="cancelamentoDialog" focus="motivoCancelamentoDialog">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="motivoCancelamentoDialog" value="Motivo Cancelamento:" />
<p:inputText id="motivoCancelamentoDialog" value="#{notaProdutoBean.notaProduto.motivoCancelamento}" />
<p:commandButton value="Cancelar" actionListener="#{notaProdutoBean.cancelarNota()}" update="status motivoCancelamento protocoloCancelamento dataCancelamento messages form"/>
</h:panelGrid>
</p:dialog>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
</p:toolbar>
<p:fieldset id='panelNotaFiscal' legend="NotaFiscal" >
<p:panelGrid columns="6" columnClasses="centered">
<p:outputLabel for='status' value='Status'/>
<p:inputText id="status" value="#{notaProdutoBean.notaProduto.status}" required="true" requiredMessage="O campo Status é obrigatório">
<p:message for="status"/>
</p:inputText>
<p:outputLabel for="motivoCancelamento" value="Motivo Cancelamento"/>
<p:inputText id="motivoCancelamento" size="25" value="#{notaProdutoBean.notaProduto.motivoCancelamento}">
<p:message for="motivoCancelamento"/>
</p:inputText>
<p:outputLabel for="protocoloCancelamento" value="Protocolo Cancelamento"/>
<p:inputText id="protocoloCancelamento" size="15" value="#{notaProdutoBean.notaProduto.protocoloCancelamento}">
<p:message for="protocoloCancelamento"/>
</p:inputText>
<p:outputLabel for="dataCancelamento" value="Data Cancelamento"/>
<p:calendar id="dataCancelamento" value="#{notaProdutoBean.notaProduto.dataCancelamento}" pattern="dd/MM/yyyy HH:mm:ss">
<p:message for='dataCancelamento'/>
</p:calendar>
</p:panelGrid>
</p:fieldset>
public void cancelarNota(){
try{
if(getNotaProduto().getStatus().equals("Autorizada")){
getNotaProduto().setStatus("Cancelada");
System.out.println("Motivo " + getNotaProduto().getMotivoCancelamento());
getNotaProduto().setProtocoloCancelamento("22222222222222");
getNotaProduto().setDataCancelamento(new Date());
new BaseBean().salvar(getNotaProduto());
RequestContext.getCurrentInstance().execute("PF('cancelamentoDialog').hide();");
}
else{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO ,"Mensagem: ", "A nota não está autorizada portanto não pode ser cancelada"));
}
}
catch(Exception e){
new Log().salvaErroLog(e);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR ,"Mensagem: ", "Um erro ocorreu, entre em conto com o adminstrador"));
}
}
You have 2 inputs for the same field in the same form:
<p:inputText id="motivoCancelamentoDialog" value="#{notaProdutoBean.notaProduto.motivoCancelamento}" />
<p:inputText id="motivoCancelamento" size="25" value="#{notaProdutoBean.notaProduto.motivoCancelamento}">
<p:message for="motivoCancelamento"/>
</p:inputText>
you should put the dialog in a separate form so it doesnt post the second input.
also you can specify the elements to process in the "cancelar" button
<p:inputText id="motivoCancelamentoDialog" value="# notaProdutoBean.notaProduto.motivoCancelamento}" />
<p:commandButton value="Cancelar" actionListener="#{notaProdutoBean.cancelarNota()}" update="status motivoCancelamento protocoloCancelamento dataCancelamento messages form" process="#this, motivoCancelamentoDialog"/>
your input tag is actually empty tag
<p:inputText id="motivoCancelamentoDialog" value="#{notaProdutoBean.notaProduto.motivoCancelamento}" />
try using something like below to see if it works.
<p:inputText id="motivoCancelamentoDialog" value="#{notaProdutoBean.notaProduto.motivoCancelamento}">abc</p:inputText>
I have a problem when I select an item from a component and when updating another component, it stops working. The strange thing is that with the application works correctly but with it breaks.
<p:panelGrid columns="#{bundle.columnas}" layout="grid" id="panel">
<p:outputLabel for="provincia" value="Provincia *" />
<p:selectOneMenu id="provincia"
value="#{inmuebleBacking.provincia}"
converter="provinciaConverter">
<f:selectItem itemLabel="Seleccione Una Provincia" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{provinciaBacking.findAllProvincias()}" var="prov" itemLabel="#{prov.provinciaNombre}" />
<p:ajax update="ciudad" listener="#{inmuebleBacking.provinciaSelecionada()}"/>
</p:selectOneMenu>
<p:outputLabel for="ciudad" value="Ciudad *" />
<h:selectOneMenu id="ciudad"
value="#{inmuebleBacking.ciudad}"
converter="ciudadConverter"
required="true">
<f:selectItem itemLabel="Seleccione Una Ciudad" itemValue="" />
<f:selectItems value="#{inmuebleBacking.ciudades}" var="ciudad" itemLabel="#{ciustrong textdad.ciudadNombre} cp: #{ciudad.cp}"/>
</h:selectOneMenu>
BackingBeans
#ViewScoped
#ManagedBean(name = "inmuebleBacking")
public class InmuebleBacking {
#EJB
private CiudadDAO ciudadDAO;
private List<Ciudad> ciudades;
public void provinciaSelecionada() {
Inmueble inmueble = (Inmueble) getEntity();
ciudades = ciudadDAO.findAllNamedBy("Ciudad.findByProvinciaId", "provinciaId", inmueble.getProvincia().getId());}
SCREENSHOTS
my problem is, that I got two fields. Here is the definition:
<h:selectOneMenu id="selectSource" update=":relationTableForm:selectObject" value="#{tabDefineRelationTable.sourceId}" style="width: 100%;" required="true" requiredMessage="Source is required">
<p:ajax listener="#{tabDefineRelationTable.handleSourceChange}" />
<f:selectItem itemLabel="Select Source" itemValue="0" noSelectionOption="true" />
<f:selectItems value="#{tabDefineRelationTable.mySources}"
update=":createArtifactForm:selectObject"
var="source"
itemLabel="#{source.s_name}"
itemValue="#{source.s_id}" />
</h:selectOneMenu>
<h:selectOneMenu id="selectObject" value="#{tabDefineRelationTable.objectId}" style="width: 100%;" required="true" requiredMessage="Object is required" onchange="submit()">
<f:selectItem itemLabel="first select Source" itemValue="0" noSelectionOption="true" />
<f:selectItems value="#{tabDefineRelationTable.myObjects}"
var="object"
itemLabel="#{object.o_name}"
itemValue="#{object.o_id}" />
</h:selectOneMenu>
I want to implement, if I select in my selectSource a field, I update the variable objectId in the backend, and see it in my frontend.
Here is my first try to implement it:
Variable definition
private List<Source> mySources;
private List<Objects> myObjects;
private Integer sourceId = 0;
private Integer objectId = 0;
Constructor:
public TabDefineRelationTable (TabLoader parent, List<Source> sources, List<Objects> objects) {
parentForm = parent;
mySources = sources;
myObjects = objects;
}
Listener:
public void handleSourceChange() {
this.objectId = 0;
if (sourceId != 0) {
for (Source curSource : mySources) {
if (curSource.getS_id() == sourceId) {
myObjects.clear();
myObjects.addAll(curSource.getObjects());
}
}
}
}
Thanks a lot.
Best regards
Björn
Update 1:
After I tried the solution to use <p:ajax event="select" update="tabView:relationTableForm:selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />,
<p:ajax event="select" update=":relationTableForm:selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" /> or
<p:ajax event="select" update=":selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />.
I got this errormessage:Cannot find component with identifier "tabView:relationTableForm:selectObject" referenced from tabView:relationTableForm:selectSource".
Any other Ideas?
Update 2:
update="#([id$=output])" testet this one. Didn't got an error, but the field is also not updated :/
could you try this..
<p:ajax update="selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
The solution was to change the ajax line into
<p:ajax update="selectObject" listener="#{tabDefineRelationTable.handleSourceChange}" />
Big thanks to serdar for help!
I have a JSF application in which I have an combobox like this.
<script type="text/javascript" defer="defer">
<!--//--><![CDATA[//><!--
helpKey = 'APPLICATION_EDIT_DATASOURCE';
function reapplyStyles() {}
function selectT(data){
if(data.status == "begin"){
$('editForm:selectTypeButton').click();
}
}
//--><!]]>
</script>
<h:form id="editForm">
<h:inputHidden id="id" value="#{applicationObject.objectId}"/>
<h:inputHidden id="type" value="#{applicationObject.object.type}"/>
<h:inputHidden id="selectedDSForApp" value="#{applicationObject.selectedDataSourceId}"/>
<ui:param name="activityDataSource" value="#{applicationObject.selectedDataSourceBean}"/>
<a4j:outputPanel id="activityDataSourceRulesPanel">
<h:panelGrid columns="2" columnClasses="padded" rowClasses="padded">
<h:outputText value="#{msgs.transformation_rule}"/>
<h:panelGroup>
<h:selectOneMenu id="dsTransformationRule" value="#{activityDataSource.selectedTransformationRule}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<f:selectItems value="#{activityDataSource.transformationRules}"/>
</h:selectOneMenu>
<ui:fragment rendered="#{sp:hasRight(facesContext, 'ManageRules')}" >
<input type="button" value="#{msgs.button_ellipsis}" class="ruleEditorBtn"
onclick="SailPoint.Rule.Editor.edit($('editForm:dsTransformationRule').value,
'ActivityTransformer',
$('editForm:refreshActivityDataSourceRulesButton'))" />
</ui:fragment>
</h:panelGroup>
<h:outputText value="#{msgs.correlation_rule}"/>
<h:panelGroup>
<h:selectOneMenu id="dsCorrelationRule" value="#{activityDataSource.selectedCorrelationRule}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<f:selectItems value="#{activityDataSource.correlationRules}"/>
</h:selectOneMenu>
<ui:fragment rendered="#{sp:hasRight(facesContext, 'ManageRules')}" >
<input type="button" value="#{msgs.button_ellipsis}" class="ruleEditorBtn"
onclick="SailPoint.Rule.Editor.edit($('editForm:dsCorrelationRule').value,
'ActivityCorrelation',
$('editForm:refreshActivityDataSourceRulesButton'))" />
</ui:fragment>
</h:panelGroup>
<h:outputText value="#{msgs.activity_data_src_type}"/>
<h:panelGroup>
<a4j:outputPanel id="collectorSettings">
<h:selectOneMenu id="collectorType"
value="#{activityDataSource.object.type}"
rendered="#{empty activityDataSource.object.id}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<!-- onchange="$('editForm:selectTypeButton').click();"> -->
<f:ajax event="change"
onevent="selectT"
execute="#this dsTransformationRule dsCorrelationRule"
render="dsTransformationRule dsCorrelationRule"
listener="#{activityDataSource.handleCollectorTypeChange}" />
<f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
<f:selectItems value="#{activityDataSource.collectorTypes}"/>
</h:selectOneMenu>
<h:selectOneMenu id="fixedCollectorType" value="#{empty activityDataSource.object.type ? 'None' : activityDataSource.object.type}"
rendered="#{not empty activityDataSource.object.id}"
disabled="true"
readonly="true">
<f:selectItem itemValue="#{empty activityDataSource.object.type ? 'None' : activityDataSource.object.type}"
itemLabel="#{empty activityDataSource.object.type ? msgs.none : activityDataSource.object.type}"/>
</h:selectOneMenu>
</a4j:outputPanel>
</h:panelGroup>
</h:panelGrid>
</a4j:outputPanel>
<a4j:outputPanel id="configSettings">
<h:messages infoClass="formInfo" warnClass="formWarn" errorClass="formError" fatalClass="formError"/>
<h:panelGroup rendered="#{not empty activityDataSource.object.collector}">
<ui:include src="#{activityDataSource.configPage}"/>
</h:panelGroup>
</a4j:outputPanel>
<h:panelGroup>
<div class="buttonRow">
<ui:fragment rendered="#{sp:hasRight(facesContext, 'ManageApplication')}">
<h:commandButton id="activityDataSourceSave" action="#{activityDataSource.saveAction}" value="#{msgs.button_save}" styleClass="primaryBtn"/>
</ui:fragment>
<h:commandButton id="activityDataSourceCancel" action="#{activityDataSource.cancelAction}" value="#{msgs.button_cancel}" styleClass="secondaryBtn"/>
</div>
</h:panelGroup>
<a4j:commandButton id="refreshActivityDataSourceRulesButton"
style="display:none"
immediate="true"
render="activityDataSourceRulesPanel"/>
<a4j:commandButton id="selectTypeButton" action="#{activityDataSource.selectType}" style="display:none"
render="configSettings, collectorSettings"
oncomplete="initializeSelectedConfigPage();"/>
</h:form>
Bean Class
public String getSelectedTransformationRule() {
if (_selectedTransformationRule == null) {
ActivityDataSourceDTO dto = getObject();
if (dto != null)
_selectedTransformationRule = dto.getTransformationRule();
}
return _selectedTransformationRule;
}
public String getSelectedCorrelationRule() {
if (_selectedCorrelationRule == null) {
ActivityDataSourceDTO dto = getObject();
if (dto != null)
_selectedCorrelationRule = dto.getCorrelationRule();
}
return _selectedCorrelationRule;
}
In the above code I have a normal onchange event & an ajax onchange event on combobox element id= collectorType.
Is there any limitation in using two change for same element in JSF.
Also how can I merge first onchange to ajax onchange.
Use onevent attribute of <f:ajax> as follows:
<h:selectOneMenu id="collectorType"
value="#{activityDataSource.object.type}"
rendered="#{empty activityDataSource.object.id}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<f:ajax event="change"
execute="#this"
render="dsTransformationRule dsCorrelationRule"
listener="#{activityDataSource.handleCollectorTypeChange}"
onevent="$('#editForm\\:selectTypeButton').click();"/>
<f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
<f:selectItems value="#{activityDataSource.collectorTypes}"/>
</h:selectOneMenu>
also notice I've modified the selector '#editForm\\:selectTypeButton' to escape the : in your button's id.
[UPDATE]
Here's what you can do to achieve the scenario we've discussed in the comments:
First to populate both dsTransformationRule and dsCorrelationRule with _selectedTransformationRule and _selectedCorrelationRule respectively, create an initialization method for them, and call it in #PostConstruct method (check Why use #PostConstruct?), so in your bean class you would have something like this:
#PostConstuct
public void init() {
initRules();
//include another things you want to be initializaed when this page finishes constructing.
}
private void initRules() {
ActivityDataSourceDTO dto = getObject();
if (dto == null)
return;
if (_selectedTransformationRule == null)
_selectedTransformationRule = dto.getTransformationRule();
if (_selectedCorrelationRule == null)
_selectedCorrelationRule = dto.getCorrelationRule();
}
//Let the getters do no dto access, so it won't matter if they're called twice on change
public String getSelectedTransformationRule() {
return _selectedTransformationRule;
}
public String getSelectedCorrelationRule() {
return _selectedCorrelationRule;
}
Now your f:ajax can normally execute and render your select menus without fearing to access your DTO layer multiple times
<f:ajax event="change" onevent="selectT"
execute="#this dsTransformationRule dsCorrelationRule"
render="dsTransformationRule dsCorrelationRule"
listener="#{activityDataSource.handleCollectorTypeChange}" />
This way, when handleCollectorTypeChange is invoked, will have both _selectedTransformationRule and _selectedCorrelationRule populated with their last selected values.
On a side note, if you want to get the values of select menus dsTransformationRule and dsCorrelationRule in a validation or conversion phase, or directly via an event listener method that is called before the Update Model Values phase, check this answer that would help you reach the value from the component.
Hopefully this would solve your issue, or at least set you in the right direction.
I have a selectOneMenu that loads anothers in demand. See:
<h:outputLabel value="Tabela: *" />
<p:selectOneMenu id="selectOneMenuTabela"
converter="entityConverter"
value="#{orcamentoMB.tabelaSelecionada}" effect="fade"
required="true" requiredMessage="A Tabela é obrigatória">
<f:selectItem itemLabel="Selecione uma Tabela" itemValue="" />
<f:selectItems value="#{orcamentoMB.tabelas}" var="tabela"
itemLabel="#{tabela.nome}" itemValue="#{tabela}" />
<p:ajax event="change" update="selectOneMenuProcedimento" />
</p:selectOneMenu>
<h:outputText value="Procedimento: *" />
<p:selectOneMenu id="selectOneMenuProcedimento"
disabled="#{orcamentoMB.tabelaSelecionada == null}"
converter="entityConverter" filter="true"
filterMatchMode="contains"
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado}"
effect="fade" required="true"
requiredMessage="O procedimento é obrigatório">
<f:selectItem itemLabel="Selecione um Procedimento" itemValue="" />
<f:selectItems value="#{orcamentoMB.tabelaSelecionada.itens}"
var="item" itemLabel="#{item.procedimento.nome}"
itemValue="#{item}" />
<p:ajax event="change"
update="localAplicacao, selectOneMenuDente,selectOneMenuFace" />
</p:selectOneMenu>
<h:outputText value="Local Aplicação: *" />
<h:outputText id="localAplicacao"
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.localAplicacao.descricao}" />
<h:outputText value="Dente: *" />
<p:selectOneMenu id="selectOneMenuDente" converter="entityConverter"
filter="true" filterMatchMode="contains"
disabled="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento == null || orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.dentesAsList.size() == 0}"
value="#{orcamentoMB.denteSelecionado}" effect="fade">
<f:selectItem itemLabel="Selecione um Dente" itemValue="" />
<f:selectItems
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.dentesAsList}"
var="dente" itemLabel="#{dente.descricao}" itemValue="#{dente}" />
</p:selectOneMenu>
<h:outputText value="Face: *" />
<p:selectOneMenu id="selectOneMenuFace" converter="entityConverter"
disabled="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.facesAplicacaoAsList.size() == 0 || orcamentoMB.itemTabelaProcedimentoSelecionado == null}"
value="#{orcamentoMB.faceSelecionada}" effect="fade">
<f:selectItem itemLabel="Selecione uma Face" itemValue="" />
<f:selectItems
value="#{orcamentoMB.itemOrcamento.itemTabelaProcedimento.procedimento.facesAplicacaoAsList}"
var="face" itemLabel="#{face.descricao}" itemValue="#{face}" />
</p:selectOneMenu>
The "selectOneMenuTabela" and "selectOneMenuProcedimento" works fine, the value are setted in ManagedBean, but the others not.
When i try to execute this commandButton bellow:
<p:commandButton value="Incluir" icon="ui-icon-plus" process="#this"
disabled="#{orcamentoMB.bean.situacao.codigo != 'AGUARDANDO_ACEITACAO'}"
update=":formManterOrcamento:tabViewManterOrcamento:tabProcedimentos,:formManterOrcamento:panelTotais"
actionListener="#{orcamentoMB.addItemOrcamento}" />
THe value inside "denteSelecionado" is null, and the values inside "selectOneMenuFace" aren't loaded.
Since you are having p:ajax event="change"on first two selectOneMenu they are being submitted that is why you are getting those value. To process them on click of commandButton add those component ids to process attribute along with #this like process like process="#this,selectOneMenuFace,selectOneMenuDente,.."
If the component is disabled or readOnly then they won't be processed.
Hope this helps