Primefaces 4.0: p:ajax partialSubmit inside compositeComponent - ajax

I'm trying to create a simple composite component based on JSF h:panelGroup:
filter.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui">
<composite:interface>
</composite:interface>
<composite:implementation>
<span>Расширенный фильтр</span>
<h:panelGroup id="#{cc.clientId}" class="filter"
style="background:white">
<composite:insertChildren></composite:insertChildren>
</h:panelGroup>
</composite:implementation>
and place a component that has to be partially submitted inside it.
<h:form id="issueFilterForm" prependId="false">
<c3:filter>
<h:panelGrid columns="2">
<h:outputText value="Продукт:" />
<p:selectOneMenu value="#{issueFilterBean.selectedProd}"
filter="true" filterMatchMode="contains">
<f:selectItem itemLabel="Выберите продукт" itemValue="-1" />
<f:selectItems value="#{issueFilterBean.products}" var="proj"
itemLabel="#{proj.name}" itemValue="#{proj.id}" />
<p:ajax event="change" process="#this" update="#form"
partialSubmit="true" />
</p:selectOneMenu>
</h:panelGrid>
</c3:filter>
</h:form>
The p:ajax call is fired, but no partial submission takes place. If i remove enclosing c3:filter, the submission works well.
How can I make this not skipping partial submission?

Related

primefaces wizard tabs update data tables

I have a page with a prime faces wizard that has 3 tabs, in my third tab there are two data tables, the first one is a list of data from a database and I have an Ajax on it that when I double click on a row it call a method to add the selected record to a different table in the same database and it gets inserted successfully and I can see it in the database table, but I want to get viewed in the second data table in my page as soon as it gets added (the second data table lists the data from my database) I have tried all the mentioned ideas on Ajax update but non of them worked for me!! can someone see what am I doing worng?
Here is my Wizard:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="/WEB-INF/layouts/exam_createor.xhtml">
<ui:define name="content">
<h:form id="frmSemesterExam">
<p:wizard id="tabsSemesterExamId" widgetVar="wiz"
flowListener="#{mbCoursesExamBank.onFlowProcess}" showNavBar="false"
showStepStatus="true">
<p:tab title="#{msg2.get('semester_exam')}" id="tabExamId">
<ui:include src="/pages/instructors/semester_course_exam.xhtml" />
</p:tab>
<p:tab title="#{msg2.get('forms')}" id="tabFormsId">
<ui:include src="/pages/instructors/exam_forms.xhtml" />
</p:tab>
<p:tab title="#{msg2.get('questions_in_this_form')}" id="tabQuestionsForm">
<ui:include src="/pages/instructors/questions_form.xhtml" />
</p:tab>
</p:wizard>
</h:form>
</ui:define>
</ui:composition>
</html>
And here is my third tab which has the dataTables:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:o="http://omnifaces.org/ui">
<p:panelGrid columns="6" id="pnlfourmData1">
<f:facet name="header">
<div align="center">#{msg2.get('exam_forms')}</div>
</f:facet>
</p:panelGrid>
<p:dataTable id="tblAllQuestions" value="#{mbInstructor.fullList}"
var="asEmp" selectionMode="single"
selection="#{mbInstructor.currentExamQuestion}" rowKey="#{asEmp.id}"
rowIndexVar="rowIndex">
<p:ajax event="rowDblselect"
update="#parent:tblAllQuestions,frmSemesterExam:tabQuestionsForm"
process="#this" listener="#{mbInstructor.submitForm()}" />
<p:column headerText="#" width="8%">
#{rowIndex+1}
</p:column>
<p:column headerText="#{msg2.get('Questions')}">
#{asEmp.questionTxt}
</p:column>
</p:dataTable>
<p:dataTable id="tblAllQuestions2" value="#{mbInstructor.formsQuestion}"
var="as" selectionMode="single"
selection="#{mbInstructor.currentExamQuestion}" rowKey="#{as.id}"
rowIndexVar="rowIndex">
<p:ajax event="rowDblselect" update="#this" process="#this" />
<p:column headerText="#" width="8%">
#{rowIndex+1}
</p:column>
<p:column headerText="#{msg2.get('Question in this form')}">
#{as.question.questionTxt}
</p:column>
</p:dataTable>
</html>
Please note that I have tried to put my dataTables inside a form and update them but did not help!

Ajax rendered jsf page doesn't bind bean values

I have a xhtml page which has a page included through a value of a bean which is updated through ajax.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<div class="ui-fluid">
<p:messages id="messages" showDetail="false" closable="true" />
<h:form id="form">
<p:panel id="panelInfo" header="Dados Local Instalação">
<h:outputLabel for="tipoFornecimento" value="Tipo de Fornecimento"/>
<p:selectOneMenu id="tipoFornecimento" value="#{cadastroController.localInstalacao.tipoFornecimento}">
<f:selectItems value="#{cadastroController.tiposFornecimento}"/>
</p:selectOneMenu>
<h:outputLabel for="familiaEquipamento" value="Família"/>
<p:selectOneMenu id="familiaEquipamento" value="#{cadastroController.familia}" required="true">
<f:selectItem itemLabel="Selecione"/>
<f:selectItems value="#{cadastroController.familias}"/>
<f:ajax listener="#{cadastroController.setarEquipamentoPelaFamilia}" render=":form:panelEquipamento"/>
</p:selectOneMenu>
</p:panel>
<p:panel id="panelEndereco" header="Endereço">
<ui:include src="/logradouro.xhtml"/>
</p:panel>
<p:panel id="equipamentoNa" header="Equipamento NA">
<ui:include src="/equipamentoNa.xhtml"/>
</p:panel>
<p:panel id="panelEquipamento" header="Equipamento">
<ui:include src="#{cadastroController.panelEquipamento}"/>
</p:panel>
<p:commandButton value="Salvar" actionListener="#{cadastroController.salvarLocalInstalacao}" ajax="false"/>
</h:form>
</div>
</h:body>
</html>
When I change the value of the selectOneMenu familiaEquipamento it triggers a method in the bean which instatiate a bean and adds the correspondent xhtml to the page
public void setarEquipamentoPelaFamilia() {
switch(familia) {
case AL:
localInstalacao.setEquipamento(new Alimentador());
setPanelEquipamento("alimentador.xhtml");
break;
case BF:
case CD:
case CDA:
case CDP:
case CO:
case CR:
case CT:
localInstalacao.setEquipamento(new ChaveFaca());
setPanelEquipamento("chaveFaca.xhtml");
break;
case FF:
case FP:
case FR:
case FT:
case FU:
localInstalacao.setEquipamento(new ChaveFusivel());
setPanelEquipamento("chaveFusivel.xhtml");
break;
case RG:
localInstalacao.setEquipamento(new BancoRegulador());
setPanelEquipamento("reguladorTensao.xhtml");
break;
case RL:
localInstalacao.setEquipamento(new Religador());
setPanelEquipamento("religador.xhtml");
break;
case BC:
localInstalacao.setEquipamento(new BancoCapacitor());
setPanelEquipamento("bancoCapacitor.xhtml");
break;
case TD:
case TDP:
localInstalacao.setEquipamento(new Trafo());
setPanelEquipamento("transformador.xhtml");
break;
case SL:
localInstalacao.setEquipamento(new Seccionalizador());
setPanelEquipamento("seccionalizador.xhtml");
break;
}
localInstalacao.getEquipamento().setFamilia(familia);
}
I.E. I choose the familia 'AL', so it sets the equipamento to new Alimentador() and returns the page 'alimentador.xhtml'.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:outputLabel for="fasesEquipamento" value="Qtd Fases: " />
<p:selectOneMenu id="fasesEquipamento" value="#{cadastroController.localInstalacao.equipamento.fases}">
<f:selectItems value="#{cadastroController.fases}"/>
</p:selectOneMenu>
<p:outputLabel for="nrAlimentador" value="Número Alimentador: " />
<p:inputMask mask="9?9" id="nrAlimentador" value="#{cadastroController.localInstalacao.equipamento.nrAlimentador}"/>
<p:outputLabel for="nrEquipamento" value="Número Equipamento: " />
<p:inputMask mask="9?9999" id="nrEquipamento" value="#{cadastroController.localInstalacao.equipamento.nrEquipamento}"/>
<p:outputLabel for="nrEquipamentoAnterior" value="Número Equipamento Anterior: " />
<p:inputMask mask="9?9999" id="nrEquipamentoAnterior" value="#{cadastroController.localInstalacao.equipamento.nrEquipamentoAnterior}"/>
<p:outputLabel for="nrSubestacao" value="Número Subestação: " />
<p:inputMask mask="9?99" id="nrSubestacao" value="#{cadastroController.localInstalacao.equipamento.nrSubestacao}"/>
<p:outputLabel for="potencia" value="Potencia: " />
<p:inputMask mask="9?99.9" id="potencia" value="#{cadastroController.localInstalacao.equipamento.potencia}"/>
<p:outputLabel for="regionalEquipamento" value="Regional: " />
<p:selectOneMenu id="regionalEquipamento" value="#{cadastroController.localInstalacao.equipamento.regional}">
<f:selectItems value="#{cadastroController.regionais}"/>
</p:selectOneMenu>
</ui:composition>
I'm using a ViewScoped ManagedBean, but after submitting the form, the values which were added through ajax in the 'alimentador.xhtml' are not binded to the bean localInstalacao
Any ideas?
Never mind, I managed to fix it by upgrading to Mojarra 2.2
It seems like a known bug described on JAVASERVERFACES - 1492
To upgrade the version of Mojarra in JBOSS AS 7.1 follow these steps Upgrading Mojarra

Action of command button not invoked if I use ajax

I have the following problem:
I have a button that should invoke a method, but the page should't get refreshed (I display a dialog based on bootstrap modal after clicking on the button and it vanishes otherwise). Therefore I use ajax to say that nothing should get rendered after clicking on the button.
I already used applied it before and it worked. But in the recent version of my code the method isn't invoked anymore as long as I use ajax. If I remove the ajax part the method is invoked as it should be, but the page gets refreshed and I don't want that.
My code:
<h:form>
<ui:fragment rendered="#{bean.condition1}">
<ui:include src="facelet1.xhtml" />
</ui:fragment>
<ui:fragment rendered="#{bean.condition2}">
<ui:include src="facelet2.xhtml" />
</ui:fragment>
<h:commandButton value="Save" action="bean.method">
<f:ajax execute="#form" render="#none"/>
</h:commandButton>
<h:form>
Before I had it like this and it worked:
<h:form>
<ui:include src="bean.faceletPath" />
<h:commandButton value="Save" action="bean.method">
<f:ajax execute="#form" render="#none"/>
</h:commandButton>
<h:form>
Thanks all,
/metalhamster
Edit:
facelet1.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition>
<h:panelGrid columns="2">
<h:outputText value="Name:">
<h:inputText value="bean.name">
<h:outputText value="Value:">
<h:inputText value="bean.value">
</h:panelGrid>
</ui:composition>
</h:body>
</html>
facelet2.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition>
<h:panelGrid columns="2">
<h:outputText value="Name:">
<h:inputText value="bean.name">
<h:outputText value="Text:">
<h:inputText value="bean.text">
</h:panelGrid>
</ui:composition>
</h:body>
</html>

Composite Component Binding is resolves to null

I am trying to bind a composite component to an ajax listener but the bind variable resolves to null. If I use the bind variable as part of the body, eg. #{bind} it does resolve properly. I assume it is a bug, but would like a second opinion before I report it. Thanks
page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:jstl="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:jfunc="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:jid1="http://mydomain.com/facelets">
<h:head></h:head>
<h:body>
<h:form id="commentBoxForm">
<jid1:confirmModal title="t" cssID="a" binding="#{bind}">
</jid1:confirmModal>
<h:commandLink value="click">
<f:ajax execute="#this" render="#form"
listener="#{bind.getFamily()}" />
</h:commandLink>
</h:form>
</h:body>
</html>
component:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:jstl="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:jfunc="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:jid1="http://mydomain.com/facelets">
<composite:interface>
<composite:attribute name="cssID" required="true" />
<composite:attribute name="title" required="true" />
</composite:interface>
<composite:implementation>
<h:panelGroup >
......
</h:panelGroup>
</composite:implementation>
</ui:composition>
This is a bug. See here for details.
A composite component binding attribute will not work properly for Ajax calls.

Action event fires only on 2nd click of commandLink/commandButton

Running Netbeans 7.1.1 with latest JRE/JDK and Glassfish 3.1 on Windows 7.0.
Despite what sort of application I build, for some reason I have to click any commandLink or commandButton twice to get event to fire.
How is this caused and how can I solve it?
Here's an example of such a view where this problem occurs:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Time Manager - New Employee</title>
</h:head>
<h:body>
<h:form id="form"">
<p:panel id="panel" header="New Employee">
<p:messages id="msgs"/>
<h:panelGrid columns="3">
<h:outputLabel for="fname" value="Firstname: *" />
<p:inputText id="fname" value="#{employee.name}"
required="true" label="FullName">
<f:validateLength minimum="2" maximum="20" />
</p:inputText>
<p:message for="fname" display="icon"/>
<h:outputLabel for="eml" value="Email: *" />
<p:inputText id="eml" value="#{employee.email}"
label="Email" required="true">
<f:validateLength minimum="9" maximum="100" />
<p:ajax update="msgEml" event="keyup" />
</p:inputText>
<p:message for="eml" id="msgEml" display="icon"/>
</h:panelGrid>
<p:button id="btn" value="Cancel" update="panel"
type="button" outcome="/index"/>
<p:commandButton id="addEmp" value="Save" update="panel"
actionListener="#{employee.saveEmployee}"
styleClass="ui-priority-primary"/>
</p:panel>
</h:form>
</h:body>
</html>

Resources