Ajax rendered jsf page doesn't bind bean values - ajax

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

Related

Primefaces 4.0: p:ajax partialSubmit inside compositeComponent

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?

Can't Display a message for a validation using jsf

I'm new to web development using JSF , i have an issue in displaying a message for a validation.
I'm trying to display a message related to length validation.
this is the code for the page :
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form>
<h:message showDetail="true" showSummary="true" for="txtNum" />
<p:panelGrid columns="2">
<p:outputLabel value="value" id="lblValue" for="txtNum" />
<p:inputText value="#{test.num}" required="true" id="txtNum">
<f:facet name="">
<f:validateLength maximum="3"></f:validateLength>
</f:facet>
</p:inputText>
<p:commandButton value="do" action="#{test.func()}"></p:commandButton>
</p:panelGrid>
</h:form>
</h:body>
</html>
this the code for the managed bean (configured from faces config):
public class Test {
private int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String func()
{
return null;
}
}
This should work. Don't forget about IDs and naming containers.When using AJAX do not skip process and update attributes.
<h:form id="form">
<p:panelGrid columns="2" id="formGrid">
<p:outputLabel value="value" id="lblValue" for=":form:txtNum" />
<p:inputText value="#{test.num}" required="true" id="txtNum">
<f:validateLength maximum="3"/>
</p:inputText>
<h:message showDetail="true" showSummary="true" for=":form:txtNum" />
<p:commandButton value="do" action="#{test.func()}" process=":form:formGrid" update=":form:formGrid"/>
</p:panelGrid>
</h:form>

primefaces calendar button disappears after validation

I have problems after click on submit button. Primafaces validation is executed and the calendars buttons dissapears.
The structure of the application view is a principal page that contains other. In the principal page which name is "welcomePrimefaces" I call to the other page wich name is left_layoutUnit using a ui:include
I am using primefaces 3.5, Mojarra 2.1.6
Somebody could help me???
welcomePrimefaces.xhtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<link type="text/css" rel="stylesheet" href="css/styles.css"/>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if(args.validationFailed || !args.loggedIn) {
jQuery('#dialog').effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" styleClass="ui-layout-header">
<ui:include src="header_layoutUnit.xhtml" />
</p:layoutUnit>
<p:layoutUnit id="footer" position="south" size="100" closable="false" collapsible="false">
<ui:include src="footer_layoutUnit.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="west" size="500" closable="false" collapsible="false">
<ui:include src="left_layoutUnit.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="center" styleClass="ui-layout-center">
<ui:include src="right_layoutUnit.xhtml" />
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
left_layoutUnit.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:form id="form">
<p:panel id="panel" header="Panel Title">
<p:messages id="msgs"/>
<p:panelGrid id="theGrid" columns="1">
<p:row>
<p:column>
<p:calendar value="#{formBean.date1}" id="popupButtonCal1" showOn="button" maxlength="8" size="15"
required="true" requiredMessage="Fecha ida is required"/>
</p:column>
</p:row>
<p:row>
<p:column>
<p:calendar value="#{formBean.date2}" id="popupButtonCal2" showOn="button" maxlength="8" size="15"
required="true" requiredMessage="Fecha vuelta is required"/>
</p:column>
</p:row>
<p:dialog header="Selected Dates" widgetVar="dialog" showEffect="fade" hideEffect="fade">
<h:panelGrid id="display" columns="1">
<h:outputText value="Popup Button Date: " />
<h:outputText id="popupButtonDate">
<f:convertDateTime pattern="d/M/yyyy"/>
</h:outputText>
</h:panelGrid>
</p:dialog>
<p:row>
<p:column>
<p:commandButton value="Submit" update="panel" actionListener="#{formBean.buscarVuelos}"/>
</p:column>
</p:row>
</p:panelGrid>
</p:panel>
</h:form>
</h:head>

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>

Ajax Validation on JSF

I want to validate required fields on diferent forms when i push on save (Toolbar.xhtml). How can i do this? Thanks in advance
I have the following code:
Father.xhtml
..
<ui:include src="/jsf/Toolbar.xhtml"/>
<ui:include src="/jsf/Adquisicion.xhtml"/>
..
Toolbar.xhtml
<ui:composition 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"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
>
<ui:insert name="toolbarComponent">
<h:form name="ToolbarForm" >
<a4j:commandLink id="save" action="#{backingBean1.save}"/>
</h:form>
</ui:insert>
</ui:composition>
Adquisicion.xhtml
<ui:composition 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"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:insert name="component">
<a4j:form id="Adquisicion">
<rich:panel>
<f:facet name="header">
<h:outputText value="Header" />
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Name" />
<h:inputText id="nameId" value="#{adquisicion.name}" style="width:500px;" required="true" requiredMessage="Required" >
<a4j:support event="onblur"/>
</h:inputText>
<rich:message for="nameId" style="color: red;"/>
</rich:panel>
<a4j:form>
</ui:insert>
<ui:composition>
The input fields have to go in the same <h:form> (or <a4j:form>, whatever you like) as the command link/button.

Resources