CommandLink has stopped after update from 2.2.1 to 3.0M4

UI Components for JSF
Post Reply
igcramos
Posts: 4
Joined: 05 Dec 2011, 16:12

09 Dec 2011, 04:39

Hi,

The commandLink "linkOfertar" have stopped to work after update to version 3.0m4. The action ""#{unitizacaoMB.setCaixaSelecionada(bean)}" is not fired. I've tried change to commandButton, but it only works if I use "ajax="false"" and that thing is awful... :? -> :( Is there a way to overcome this?

The page's code follows, thank you!

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	
	<h:form prependId="false">
		<p:dataTable id="tabelaUnitizacoes" var="bean"
			value="#{unitizacaoMB.unitizacoesCadastradas}" lazy="true"
			rows="#{unitizacaoMB.paginationConfig.pageSize}"
			pageLinks="#{unitizacaoMB.paginationConfig.maxPageLinks}"
			paginator="true" paginatorAlwaysVisible="false" 
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
			emptyMessage="#{messages['tabela.msg.sem.registro']}" loadingMessage="#{messages['tabela.msg.carregando']}"
			errorMessage="#{messages['tabela.msg.erro']}" style="width:100%">
			
			<p:column>
				<f:facet name="header">#{messages['dataTable.ofertar']}</f:facet>
				<p:commandLink id="linkOfertar" ajax="true" action="#{unitizacaoMB.setCaixaSelecionada(bean)}" 
						update="idPanelConfirmLoginEstoque" oncomplete="confirmacaoLoginEstoque.show()"
						process="@this" immediate="true"
						styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
					<span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
					<span class="ui-button-text">ui-button</span>
				</p:commandLink>		
			</p:column>
			<p:column sortBy="#{bean.produto.nome}" filterBy="#{bean.produto.nome}">
				<f:facet name="header">#{messages['unitizacao.produto']}</f:facet>
				<h:outputText value="#{bean.produto.nome} "/>
				<h:outputText value="#{bean.categoria.nome}-"/>
				<h:outputText value="#{bean.padrao.nome} #{bean.padrao.valor} -"/>
				<h:outputText value="#{bean.embalagem.nome}-"/>
				<h:outputText value="#{bean.marca.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.paisOrigem.nome}" filterBy="#{bean.paisOrigem.nome}">
				<f:facet name="header">#{messages['unitizacao.pais']}</f:facet>
				<h:outputText value="#{bean.paisOrigem.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.eta}" >
				<f:facet name="header">#{messages['unitizacao.eta']}</f:facet>
				<h:outputText value="#{bean.eta}">
					<f:convertDateTime type="date" pattern="w '-' dd/MM/yyyy"/>
				</h:outputText>
			</p:column>
			<p:column sortBy="#{bean.pallet.quantidade}">
				<f:facet name="header">#{messages['unitizacao.pallet']}</f:facet>
				<h:outputText value="#{bean.pallet.quantidade}"/> - (<h:outputText value="#{bean.quantidade}"/>)
			</p:column>
			<p:column sortBy="#{bean.preco}">
				<f:facet name="header">#{messages['unitizacao.preco']}</f:facet>
				<h:outputText value="#{bean.preco}">
					<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="#{localeConfig.localidadeMonetaria}"/>
				</h:outputText> - <h:outputText value="#{bean.incoterm.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.armazem.nome}">
				<f:facet name="header">#{messages['unitizacao.armazem']}</f:facet>
				<h:outputText value="#{bean.armazem.nome}"/>
			</p:column>
			<p:column>
				<p:commandLink ajax="true" action="#{unitizacaoMB.setCaixaSelecionada(bean)}" 
						update="panelInfoDialogMeuEstoque" oncomplete="infoDialog.show();">
					<h:outputText value="#{messages['unitizacao.info']}"/>
				</p:commandLink>													
			</p:column>
			<p:column rendered="#{exibirBotoesAlteracao}">
				<f:facet name="header">#{messages['dataTable.alterar']}</f:facet>
				<p:commandButton action="#{unitizacaoMB.preUpdate}"
						process="@this" immediate="true" update="idToolbar,fieldSetPallet,fieldSetCaixa"
						image="ui-icon-pencil">
					<f:setPropertyActionListener value="#{bean}" target="#{unitizacaoMB.caixaSelecionada}"/>
				</p:commandButton>
			</p:column>
			<p:column rendered="#{exibirBotoesAlteracao}">
				<f:facet name="header">#{messages['dataTable.excluir']}</f:facet>
				<p:commandButton id="linkDelete" onclick="confirmacaoDelete.show()"
						process="@this" immediate="true" image="ui-icon-trash">
					<f:setPropertyActionListener value="#{bean}" target="#{unitizacaoMB.caixaSelecionada}" for="linkDelete"/>
				</p:commandButton>
			</p:column>
		</p:dataTable>
				
		<p:confirmDialog width="300" height="130" message="#{messages['label.confirm.delete']}" showEffect="fade" hideEffect="fade"
				header="#{messages['label.dialog.delete']}" severity="alert" widgetVar="confirmacaoDelete" modal="true" appendToBody="true">
			<p:commandButton id="botaoConfirmaDeletar" value="#{messages['button.dialog.yes']}" action="#{unitizacaoMB.deleteCaixa}" 
				immediate="true" ajax="true" update="messages,tabelaUnitizacoes" oncomplete="confirmacaoDelete.hide();">
			</p:commandButton>
			<p:commandButton value="#{messages['button.dialog.no']}" onclick="confirmacaoDelete.hide();"/>	
		</p:confirmDialog>
		
		<ui:include src="../componentes/infoCaixa.xhtml">
			<ui:param name="idPanelInfoCaixa" value="panelInfoDialogMeuEstoque"/>
			<ui:param name="widgetVarDialogInfoCaixa" value="infoDialog" />
			<ui:param name="mbInfoCaixa" value="#{unitizacaoMB}" />				
		</ui:include>
		
		<ui:include src="../componentes/operacaoSolicitarSenha.xhtml">
			<ui:param name="complementoID" value="LoginEstoque"/>
			<ui:param name="mbOperacaoComSenha" value="#{unitizacaoMB}"/>
			<ui:param name="elementosParaAtualizar" value="tabelaUnitizacoes,tabelaUnitizacoesOfertadas"/>
			<ui:param name="acaoConfirmar" value="oferecerCaixa"/>
		</ui:include>
	</h:form>
</ui:composition>

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

10 Dec 2011, 00:38

1. Did you try to replace action= with actionListener="#{bean.method(bean)}" ?
2. Can you reply with your bean?
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

igcramos
Posts: 4
Joined: 05 Dec 2011, 16:12

10 Dec 2011, 22:13

Hi, Autobot!

First of all, tks! here we go:

1. Did you try to replace action= with actionListener="#{bean.method(bean)}" ?

Actually, I've tried everything action, actionListener... even with commandbutton! The request doesn't arrived there. I've tried to use "<f:setPropertyActionListener value="#{bean}"target="#{bean.method}"/>", <f:param name="id" value="#{bean.id}"/> and nothing worked too for both, commandLink and commandButton... :(

Sincerely, I'm feeling very disappointed with that, because everything was working perfectly at 2.2.1, I only wanna use the brand new push support.

Well, I'll try a little bit more before do SVN "revert" and go back to 2.2.1, again. :(

p.s: I'm taking "WARN [org.apache.tomcat.util.http.Parameters] Parameters: Invalid chunk ignored." at the console and I'm using JBossAS [6.1.0.SNAPSHOT "Neo"] and Mojarra-2.0

2. Can you reply with your bean?

Code: Select all

...

@ViewController
@NextView("/private/pages/unitizacao/unitizacao_edit.xhtml")
public class UnitizacaoMB extends FBListEditPageBean<Caixa, CaixaBC> {

	private static final long serialVersionUID = -7897967422626728996L;

	private boolean isPallet;
	private boolean isUpdateMode = false;
	private boolean isClonar;
	private Caixa caixaSelecionada;
	private Caixa caixa;
	private List<FotoUnitizacao> fotosUnitizacao = new ArrayList<FotoUnitizacao>();
	private Produto produtoFavorito;
	private VetorOpcoesProduto vetorProdutoSelecionado;

	private LazyDataModel<Caixa> unitizacoesCadastradas;
	private LazyDataModel<Caixa> unitizacoesOfertadas;
	private List<CertificadoProduto> certificadosProduto;

	@Inject
	private CaixaBC caixaBC;
	@Inject
	private PalletBC palletBC;
	@Inject
	private ArmazemBC armazemBC;
	@Inject
	private CategoriaBC categoriaBC;
	@Inject
	private EmbalagemBC embalagemBC;
	@Inject
	private IncotermBC incotermBC;
	@Inject
	private MarcaBC marcaBC;
	@Inject
	private ProdutoBC produtoBC;
	@Inject
	private PessoaJuridicaBC pessoaJuridicaBC;
	@Inject
	private PaisBC paisBC;
	@Inject
	private FotoUnitizacaoBC fotoUnitizacaoBC;
	@Inject
	private PadraoBC padraoBC;
	@Inject
	private PessoaFisicaBC pessoaFisicaBC;
	@Inject
	private UsuarioBC usuarioBC;
	@Inject
	private RelatorioConfig relatorioConfig;
	@Inject
	private CertificadoProdutoBC certificadoProdutoBC;

	//construtores
	public UnitizacaoMB() {
		this.inicializarMB();
	}

	@Override
	protected CaixaBC getBC() {
		return this.caixaBC;
	}

	public boolean isPallet() {
		return this.isPallet;
	}

	public void setPallet(boolean isPallet) {
		this.isPallet = isPallet;
	}

	public boolean isClonar() {
		return this.isClonar;
	}

	public void setClonar(boolean isClonar) {
		this.isClonar = isClonar;
	}

	public Produto getProdutoFavorito() {
		return this.produtoFavorito;
	}

	public void setProdutoFavorito(Produto produtoFavorito) {
		this.produtoFavorito = produtoFavorito;
	}

	public Caixa getCaixaSelecionada() {
		return this.caixaSelecionada;
	}

	public void setCaixaSelecionada(Caixa caixaSelecionada) {
		this.caixaSelecionada = caixaSelecionada;
	}

	public Caixa getCaixa() {
		return this.caixa;
	}

	public void setCaixa(Caixa caixa) {
		this.caixa = caixa;
	}

	public List<FotoUnitizacao> getFotosUnitizacao() {
		return this.fotosUnitizacao;
	}

	public LazyDataModel<Caixa> getUnitizacoesCadastradas() {
		return this.unitizacoesCadastradas;
	}

	public LazyDataModel<Caixa> getUnitizacoesOfertadas() {
		return this.unitizacoesOfertadas;
	}

	public List<CertificadoProduto> getCertificadosProduto() {
		return this.certificadosProduto;
	}

	private void inicializarMB() {
		this.caixa = new Caixa();
		this.isPallet = true;
		this.isClonar = false;
		this.isUpdateMode = false;

		this.fotosUnitizacao = new ArrayList<FotoUnitizacao>();

		this.caixa.setArmazem(new Armazem());
		this.caixa.setCategoria(new Categoria());
		this.caixa.setEmbalagem(new Embalagem());
		this.caixa.setIncoterm(new Incoterm());
		this.caixa.setMarca(new Marca());
		this.caixa.setPaisOrigem(new Pais());
		this.caixa.setPallet(new Pallet());
		this.caixa.setProduto(new Produto());
		this.caixa.setPadrao(new Padrao());
		this.setProdutoFavorito(new Produto());
		this.certificadosProduto = new ArrayList<CertificadoProduto>();

		this.unitizacoesCadastradas = new LazyDataModel<Caixa>(){
			private static final long serialVersionUID = 5184309991174890810L;

			@Override
			public Caixa getRowData(String chave) {
				return UnitizacaoMB.this.getBC().load(new Long(chave));
			}

			@Override
			public Object getRowKey(Caixa obj) {
				return obj.getId();
			}

			@Override
			public List<Caixa> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
				List<Caixa> retorno = UnitizacaoMB.this.carregarUnitizacoes(first, pageSize, sortField, sortOrder, filters, false);
				this.setRowCount(retorno.size());

				return retorno;
			}
		};
		this.unitizacoesCadastradas.setPageSize(1);
		this.unitizacoesOfertadas = new LazyDataModel<Caixa>(){
			private static final long serialVersionUID = -5659597772563674592L;

			@Override
			public Caixa getRowData(String chave) {
				return UnitizacaoMB.this.getBC().load(new Long(chave));
			}

			@Override
			public Object getRowKey(Caixa obj) {
				return obj.getId();
			}

			@Override
			public List<Caixa> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
				List<Caixa> retorno = UnitizacaoMB.this.carregarUnitizacoes(first, pageSize, sortField, sortOrder, filters, true);
				this.setRowCount(retorno.size());

				return retorno;
			}
		};
		this.unitizacoesOfertadas.setPageSize(1);
	}

	/*
	 * public void selecionarCaixa(ActionEvent evt) {
	 * Caixa caixa = (Caixa) evt.getComponent().getAttributes().get("caixa");
	 * if(caixa != null) {
	 * this.caixaSelecionada = caixa;
	 * }
	 * }
	 */

	/**
	 * Filtra os certificados para a seleção do usuário. Usa para o filtro o
	 * texto digitado no campo, mas
	 * leva em consideração o produto escolhido, caso um tenha sido.
	 * 
	 * @param q
	 * @return
	 */
	public List<CertificadoProduto> filtrarCertificados(String q) {
		Filter<CertificadoProduto> filter = new Filter<CertificadoProduto>();
		filter.getPage().setFirstResult(0);
		filter.getPage().setPageSize(7);

		filter.addLikeIgnoreCase("numeroCertificado", q);

		if(this.vetorProdutoSelecionado != null) { // Só pesquisar certificados do produto selecinado, se um estiver.
			filter.addEquals("$produtos.id", this.vetorProdutoSelecionado.getProduto().getId());
		}
		return this.certificadoProdutoBC.findAll(filter);
	}

	/**
	 * Adiciona certificado selecionado à lista que os armazena.
	 * 
	 * @param event
	 */
	public void selecionarCertificado(SelectEvent evt) {
		Filter<CertificadoProduto> filter = new Filter<CertificadoProduto>();
		filter.addEquals("id", new Long((String) evt.getObject()));

		CertificadoProduto cert = this.certificadoProdutoBC.find(filter);

		if(!this.certificadosProduto.contains(cert) && this.certificadosProduto.size() <= 14) {
			this.certificadosProduto.add(cert);
		}
		((AutoComplete) evt.getSource()).resetValue();
		FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("autoComplete_certificados");
	}

	/**
	 * Controla a lista interna de ids dos Certificados selecionados na tela.
	 * 
	 * @param evt
	 */
	public void apagarCertificado(ActionEvent evt) {
		CertificadoProduto cert = (CertificadoProduto) evt.getComponent().getAttributes().get("certificado");

		if(this.certificadosProduto.remove(cert)) {
			FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("tabela_certificados_list");
		}
	}

	/**
	 * 
	 * @param q
	 * @return
	 */
	public List<VetorOpcoesProduto> filtrarProdutos(String q) {
		List<VetorOpcoesProduto> retorno = null;
		if(!FBUtil.isBrancoOuNulo(q)) {
			retorno = this.produtoBC.consultarVetoresProduto(q);
		} else {
			retorno = new ArrayList<VetorOpcoesProduto>();
		}
		return retorno;
	}

	/**
	 * Armazena o produto selecionado no campo autoComplete e atualiza a lista
	 * de certificados
	 * selecionados, se houver algum, para que só os certificados do tal produto
	 * sejam exibidos.
	 * 
	 * @param event
	 */
	public void selecionarProduto(SelectEvent evt) {
		this.vetorProdutoSelecionado = (VetorOpcoesProduto) evt.getObject();

		for (int i = 0; i < this.certificadosProduto.size(); i++) {
			CertificadoProduto cert = this.certificadosProduto.get(i);

			if(!cert.getProdutos().contains(this.vetorProdutoSelecionado.getProduto())) {
				this.certificadosProduto.remove(i);
				i--;
			}
		}
	}

	private void carregarEntidadesCaixa() {
		this.carregarCombos();
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getPallet())) {
			this.caixa.setPallet(this.palletBC.load(this.caixa.getPallet().getId()));
		}
		if(this.vetorProdutoSelecionado != null) {
			this.caixa.setProduto(this.produtoBC.load(this.vetorProdutoSelecionado.getProduto().getId()));
			this.caixa.setCategoria(this.categoriaBC.load(this.vetorProdutoSelecionado.getCategoria().getId()));
			this.caixa.setPadrao(this.padraoBC.load(this.vetorProdutoSelecionado.getPadrao().getId()));
			this.caixa.setEmbalagem(this.embalagemBC.load(this.vetorProdutoSelecionado.getEmbalagem().getId()));
		}
		this.caixa.setCertificados(this.certificadosProduto);
	}

	private void carregarEntidadesPallet() {
		if(this.caixa != null) {
			if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getPaisOrigem())) {
				this.caixa.setPaisOrigem(this.paisBC.load(this.caixa.getPaisOrigem().getId()));
			}
			if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getArmazem())) {
				this.caixa.setArmazem(this.armazemBC.load(this.caixa.getArmazem().getId()));
			}
			if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getIncoterm())) {
				this.caixa.setIncoterm(this.incotermBC.load(this.caixa.getIncoterm().getId()));
			}
		}
	}

	private void carregarCombos() {
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getArmazem())) {
			this.caixa.setArmazem(this.armazemBC.load(this.caixa.getArmazem().getId()));
		}
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getIncoterm())) {
			this.caixa.setIncoterm(this.incotermBC.load(this.caixa.getIncoterm().getId()));
		}
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getMarca())) {
			this.caixa.setMarca(this.marcaBC.load(this.caixa.getMarca().getId()));
		}
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getPaisOrigem())) {
			this.caixa.setPaisOrigem(this.paisBC.load(this.caixa.getPaisOrigem().getId()));
		}
	}

	@Override
	public void clear() {
		super.clear();
		this.inicializarMB();
	}

	protected void clearClonar() {
		super.clear();

		this.fotosUnitizacao = new ArrayList<FotoUnitizacao>();

		Caixa caixaClone = new Caixa();
		caixaClone.setPallet(new Pallet());

		caixaClone.setArmazem(this.caixa.getArmazem());
		caixaClone.setCategoria(this.caixa.getCategoria());
		caixaClone.setCertificados(this.caixa.getCertificados());
		caixaClone.setEmbalagem(this.caixa.getEmbalagem());
		caixaClone.setEta(this.caixa.getEta());
		caixaClone.setIncoterm(this.caixa.getIncoterm());
		caixaClone.setMarca(this.caixa.getMarca());
		caixaClone.setObservacao(this.caixa.getObservacao());
		caixaClone.setPaisOrigem(this.caixa.getPaisOrigem());
		caixaClone.setPreco(this.caixa.getPreco());
		caixaClone.setProduto(this.caixa.getProduto());
		caixaClone.setQuantidade(this.caixa.getQuantidade());
		caixaClone.setPadrao(this.caixa.getPadrao());
		caixaClone.setClasse(this.caixa.getClasse());

		caixaClone.getPallet().setQuantidade(this.caixa.getPallet() != null ? this.caixa.getPallet().getQuantidade() : null);

		this.caixa = caixaClone;
	}

	public List<Categoria> getCategorias() {
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getProduto())) {
			Filter<Categoria> filtro = new Filter<Categoria>();
			filtro.addEquals("produto.id", this.caixa.getProduto().getId());
			return this.categoriaBC.findAll(filtro);
		}
		return null;
	}

	public List<Padrao> getPadroes() {
		if(!FBUtil.isIdFBPojoNullOuZero(this.caixa.getProduto())) {
			Filter<Padrao> filtro = new Filter<Padrao>();
			filtro.addEquals("produto.id", this.caixa.getProduto().getId());
			return this.padraoBC.findAll(filtro);
		}
		return null;
	}

	@Transactional
	public String insertCaixa() {
		this.caixa.setVendedor(this.pessoaJuridicaBC.load(FBUtil.getUsuarioSessao().getPessoaFisica().getEmpresa().getId()));

		this.realizarInsercaoCaixa();

		this.gravarFotosDisco();
		this.fotoUnitizacaoBC.insert(this.fotosUnitizacao);

		this.getBC().update(this.caixa);

		if(this.isClonar()) {
			this.clearClonar();
		} else {
			this.clear();
		}
		this.messageContext.add(InfoMessage.INSERIR_OK);

		return null;
	}

	private void realizarInsercaoCaixa() {
		if(this.isPallet()) {
			this.carregarEntidadesPallet();
			this.caixa.getPallet().setPaisOrigem(this.caixa.getPaisOrigem());
			this.caixa.getPallet().setEta(this.caixa.getEta());
			this.caixa.getPallet().setVendedor(this.caixa.getVendedor());
			this.caixa.getPallet().setClasse(this.caixa.getClasse());
			this.caixa.getPallet().setArmazem(this.caixa.getArmazem());
			this.caixa.getPallet().setIncoterm(this.caixa.getIncoterm());
			this.palletBC.insert(this.caixa.getPallet());
		}
		this.carregarEntidadesCaixa();

		if(!this.isPallet()) {
			this.caixa.setPallet(null);
		}
		this.getBC().insert(this.caixa);
	}

	@Transactional
	public void deleteCaixa() {
		this.getBC().delete(this.caixaSelecionada.getId());
		this.messageContext.add(InfoMessage.APAGAR_OK);
	}

	@Transactional
	public void oferecerCaixa() {
		this.usuarioBC.validarConfirmacaoLogin(this.getPasswordLogin());

		Caixa caixaOferecida = this.getBC().load(this.caixaSelecionada.getId());

		caixaOferecida.setOfertado(true);
		this.getBC().update(caixaOferecida);

		this.setPasswordLogin(null);
		this.messageContext.add(InfoMessage.OFERECER_UNITIZACAO_OK);
	}

	/**
	 * Método que retira, mediante senha, uma oferta e a transfere novamente
	 * para o estoque.
	 */
	@Transactional
	public void desofertarCaixa() {
		this.usuarioBC.validarConfirmacaoLogin(this.getPasswordLogin());

		Caixa caixaOferecida = this.getBC().load(this.caixaSelecionada.getId());

		caixaOferecida.setOfertado(false);
		this.getBC().update(caixaOferecida);

		this.setPasswordLogin(null);
		this.messageContext.add(InfoMessage.ESTOCAR_UNITIZACAO_OK);
	}

	public String preUpdate() {
		this.caixa = this.getBC().load(this.caixaSelecionada.getId());

		this.isUpdateMode = true;
		this.isClonar = false;

		if(FBUtil.isIdFBPojoNullOuZero(this.caixa.getPallet())) {
			this.isPallet = false;
		} else {
			this.isPallet = true;
		}
		return null;
	}

	@Override
	public boolean isUpdateMode() {
		return this.isUpdateMode;
	}

	@Transactional
	public String updateCaixa() {
//		this.validarCamposObrigatoriosInsert();

		this.carregarCombos();

		if(this.isPallet() && this.caixa.getPallet() != null) {
			this.carregarEntidadesPallet();
			this.caixa.getPallet().setPaisOrigem(this.caixa.getPaisOrigem());
			this.caixa.getPallet().setEta(this.caixa.getEta());
			this.caixa.getPallet().setVendedor(this.caixa.getVendedor());
			this.caixa.getPallet().setClasse(this.caixa.getClasse());
			this.caixa.getPallet().setArmazem(this.caixa.getArmazem());
			this.caixa.getPallet().setIncoterm(this.caixa.getIncoterm());
		}

		if(FBUtil.isVazioOuNulo(this.caixa.getFotos())) {
			this.caixa.setFotos(new ArrayList<FotoUnitizacao>());
		}

		this.gravarFotosDisco();
		this.fotoUnitizacaoBC.insert(this.fotosUnitizacao);

		this.getBC().update(this.caixa);
		this.isUpdateMode = false;

		if(this.isClonar()) {
			this.clearClonar();
		} else {
			this.clear();
		}
		this.messageContext.add(InfoMessage.ATUALIZAR_OK);

		return null;
	}

	public void uploadFoto(FileUploadEvent fileEvent) {
		FotoUnitizacao fotoUnitizacao = new FotoUnitizacao();
		fotoUnitizacao.setNomeArquivoUpload(fileEvent.getFile().getFileName());

		try {
			fotoUnitizacao.setStreamFotoUpload(fileEvent.getFile().getInputstream());
		} catch (Exception e) {
			throw new FBException(ErrorMessage.ERRO_UPLOAD_ARQUIVO, e);
		}

		this.fotoUnitizacaoBC.gravarFotoTemporariaDisco(FBUtil.getUsuarioSessao(), fotoUnitizacao);

		try {
			fotoUnitizacao.setStreamFotoUpload(fileEvent.getFile().getInputstream());
		} catch (Exception e) {
			throw new FBException(ErrorMessage.ERRO_UPLOAD_ARQUIVO, e);
		}
		this.fotosUnitizacao.add(fotoUnitizacao);
	}

	private void gravarFotosDisco() {
		if(!FBUtil.isVazioOuNulo(this.fotosUnitizacao)) {
			for (FotoUnitizacao fotoUnitizacao : this.fotosUnitizacao) {
				fotoUnitizacao.setUnitizacao(this.caixa);
			}
			this.fotoUnitizacaoBC.removerFotosTemporariasDisco(FBUtil.getUsuarioSessao(), this.fotosUnitizacao);
			this.fotoUnitizacaoBC.gravarFotosDisco(FBUtil.getUsuarioSessao(), this.fotosUnitizacao);
		}
	}

	public String gerarEEnviarDailyOfferReport() {
		List<PessoaJuridica> empresas = this.pessoaJuridicaBC.findAll();

		for (PessoaJuridica empresa : empresas) {
			List<ParceiroComercial> parceirosVendedores = new ArrayList<ParceiroComercial>(empresa.getParceriaVendedores());

			if(!FBUtil.isVazioOuNulo(parceirosVendedores)) {
				List<Caixa> ofertasParaAEmpresa;
				List<Long> listaIdsParceiros = new ArrayList<Long>();

				for (ParceiroComercial parceiroVendedor : parceirosVendedores) {
					listaIdsParceiros.add(parceiroVendedor.getVendedor().getId());
				}

				Filter<Caixa> filtroCaixas = new Filter<Caixa>();
				filtroCaixas.addEquals("ofertado", true);
				filtroCaixas.addIn("vendedor.id", listaIdsParceiros);

				filtroCaixas.addOrder("produto.nome", Filter.ASC);
				filtroCaixas.addOrder("categoria.nome", Filter.ASC);
				filtroCaixas.addOrder("padrao.nome", Filter.ASC);
				filtroCaixas.addOrder("embalagem.nome", Filter.ASC);
				filtroCaixas.addOrder("preco", Filter.ASC);

				ofertasParaAEmpresa = this.caixaBC.findAll(filtroCaixas);

				if(!FBUtil.isVazioOuNulo(ofertasParaAEmpresa)) {
					Map<String, Object> params = new HashMap<String, Object>();

					Caixa caixaPromocional = ofertasParaAEmpresa.get(0);

					params.put("PROMO_FRUTA", caixaPromocional.getProduto().getNome());
					params.put("PROMO_VARIEDADE", caixaPromocional.getCategoria().getNome());
					params.put("PROMO_PADRAO", caixaPromocional.getPadrao().getNome());
					params.put("PROMO_PRECO", caixaPromocional.getPreco());
					params.put("PROMO_MARCA", caixaPromocional.getMarca().getNome());
					params.put("NOME_COLUNA_FRUTA", this.relatorioConfig.getNomeColunaFruta());
					params.put("NOME_COLUNA_VARIEDADE", this.relatorioConfig.getNomeColunaVariedade());
					params.put("NOME_COLUNA_PADRAO", this.relatorioConfig.getNomeColunaPadrao());
					params.put("NOME_COLUNA_PACK", this.relatorioConfig.getNomeColunaPack());
					params.put("NOME_COLUNA_MIN", this.relatorioConfig.getNomeColunaMin());
					params.put("NOME_COLUNA_MAX", this.relatorioConfig.getNomeColunaMax());

					Collection<FotoUnitizacao> fotosCaixaPromocional = caixaPromocional.getFotos();
					boolean temFoto = !fotosCaixaPromocional.isEmpty();

					if(temFoto) {
						fotosCaixaPromocional.iterator().next();

						params.put("PROMO_FOTO", null);
					} else {
						params.put("PROMO_FOTO", null);
					}
					params.put("TITULO", "fruitbook");
					params.put("TEM_OFERTAS", Boolean.valueOf(true));

					/*
					 * TODO Adicionar regra de negócio para as promoções
					 * especiais
					 */
					params.put("TEM_PROMOCAO", Boolean.valueOf(true));

					Filter<PessoaFisica> filtroPessoasFisicasDaEmpresa = new Filter<PessoaFisica>();
					filtroPessoasFisicasDaEmpresa.addEquals("empresa.id", empresa.getId());

					List<PessoaFisica> pessoasFisicasDaEmpresa = this.pessoaFisicaBC.findAll(filtroPessoasFisicasDaEmpresa);

					for (PessoaFisica pessoaFisica : pessoasFisicasDaEmpresa) {
						FBEmail.enviarEmailDailyOfferReport(ofertasParaAEmpresa, params, pessoaFisica.getEmail());
					}
				} else {
					/*
					 * Não há ofertas para o envio
					 * do DailyOfferReport
					 */
				}
			} else {
				/*
				 * Não há parceiros comerciais para a geração
				 * do DailyOfferReport.
				 */
			}
		}
		return "";
	}

	/**
	 * Chamada para preencher a tabela de Unitizações Cadastradas. Responsável
	 * por controlar o comportamento da mesma.
	 * 
	 * @param first
	 * @param pageSize
	 * @param sortField
	 * @param sortOrder
	 * @param filters
	 * @return
	 */
	private List<Caixa> carregarUnitizacoes(
			int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters, boolean oferta) {

		Filter<Caixa> filtroCaixas = new Filter<Caixa>();
		filtroCaixas.getPage().setFirstResult(first);
		filtroCaixas.getPage().setPageSize(pageSize);

		filtroCaixas.addEquals("vendedor.id", FBUtil.getUsuarioSessao().getPessoaFisica().getEmpresa().getId());
		filtroCaixas.addEquals("ofertado", oferta);

		if(!FBUtil.isVazioOuNulo(filters)) {
			for (Entry<String, String> entry : filters.entrySet()) {
				filtroCaixas.addLikeIgnoreCase(entry.getKey(), entry.getValue());
			}
		}

		if(FBUtil.isBrancoOuNulo(sortField)) {
			filtroCaixas.addOrder("produto.nome", Filter.ASC);
		} else {
			String order = sortOrder == SortOrder.ASCENDING ? Filter.ASC : Filter.DESC;
			filtroCaixas.addOrder(sortField, order);
		}
		List<Caixa> caixasCadastradas = UnitizacaoMB.this.getBC().findAll(filtroCaixas);

		return caixasCadastradas;
	}
}
Again, thanks for your attention.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

11 Dec 2011, 07:31

Well, I surely don't want to see you SVN "revert". :)

1. What happens if you remove prependId="false" ?

Code: Select all

<h:form prependId="false">
2. You may need to do something like as follows: update=":form:idPanelConfirmLoginEstoque" where form is the form ID that contains idPanelConfirmLoginEstoque.

3. Well, if I am correct, oncomplete="javascript..." works with ajax="true". Does the dialog show?

Code: Select all

            <p:commandLink id="linkOfertar" ajax="true" action="#{unitizacaoMB.setCaixaSelecionada(bean)}" 
                  update="idPanelConfirmLoginEstoque" oncomplete="confirmacaoLoginEstoque.show()"
                  process="@this" immediate="true"
                  styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
               <span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
               <span class="ui-button-text">ui-button</span>
            </p:commandLink>      
5. Last but not least, please reply with your development/test environment similar to what I listed in my signature below. I'm wondering if you're using older version of JSF (for example, JSF 1.2 instead of 2.x), which may not be working well with PF3.0M4.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

igcramos
Posts: 4
Joined: 05 Dec 2011, 16:12

11 Dec 2011, 16:26

Hi there!

My development environment: Eclipse Helios, Mojarra 2.0.3 ( b05), Jboss 6.1 SNAPSHOT

1. What happens if you remove prependId="false" ?

Well, nothing changed.

2. You may need to do something like as follows: update=":form:idPanelConfirmLoginEstoque" where form is the form ID that contains idPanelConfirmLoginEstoque.

A. Believe, I did it.

3. Well, if I am correct, oncomplete="javascript..." works with ajax="true". Does the dialog show?

A. Yes, It does.



However, there are differences between 2.2.1 and 3.0RC1-SNAPSHOT generated HTML, is that correct?

with Primefaces 3.0RC1

- commandButton and commandLink:

Code: Select all

 <button id="formMeuEstoque:tabelaUnitizacoes:0:botaoOfertar" name="formMeuEstoque:tabelaUnitizacoes:0:botaoOfertar" 

onclick="PrimeFaces.ab

({formId:'formMeuEstoque',source:'formMeuEstoque:tabelaUnitizacoes:0:botaoOfertar',process:'formMeuEstoque:tabelaUnitizacoes:0:botaoOfert

ar',update:':formMeuEstoque:idPanelConfirmLoginEstoque',oncomplete:function(xhr, status, args){confirmacaoLoginEstoque.show();}});return 

false;" type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" role="button" aria-

disabled="false"><span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span><span class="ui-button-text">ui-

button</span></button>

with primefaces 2.2.1

- commandButton and commandLink:

Code: Select all

<button id="tabelaUnitizacoes:1:botaoOfertar" name="tabelaUnitizacoes:1:botaoOfertar" onclick="PrimeFaces.ajax.AjaxRequest

('/myapp/private/pages/unitizacao/unitizacao_edit.jsf',

{formId:'formMeuEstoque',async:false,global:true,source:'tabelaUnitizacoes:1:botaoOfertar',process:'tabelaUnitizacoes:1:botaoOfertar',upd

ate:'idPanelConfirmLoginEstoque',oncomplete:function(xhr, status, args){confirmacaoLoginEstoque.show();}});return false;" type="submit" 

class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" role="button" aria-disabled="false" title="ui-

button"><span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span><span class="ui-button-text">ui-button</span></button>

Both using the follow .xhtml, but with the same bean:

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<h:form id="formMeuEstoque" prependId="false">
		<p:dataTable id="tabelaUnitizacoes" var="bean"
			value="#{unitizacaoMB.unitizacoesCadastradas}" lazy="true"
			rows="#{unitizacaoMB.paginationConfig.pageSize}"
			pageLinks="#{unitizacaoMB.paginationConfig.maxPageLinks}"
			paginatorAlwaysVisible="false" paginator="true"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} 

{LastPageLink}"
			emptyMessage="#{messages['tabela.msg.sem.registro']}" loadingMessage="#{messages['tabela.msg.carregando']}"
			errorMessage="#{messages['tabela.msg.erro']}" style="width:100%">
			
			<p:column>
				<f:facet name="header">#{messages['dataTable.ofertar']}</f:facet>						

		
				<!--<p:commandLink id="linkOfertar" ajax="true" action="#{unitizacaoMB.setCaixaSelecionada(bean)}" 
						update="idPanelConfirmLoginEstoque" oncomplete="confirmacaoLoginEstoque.show()"
						process="@this" immediate="true"
						styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
					<span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
					<span class="ui-button-text">ui-button</span>
				</p:commandLink>-->
				<p:commandButton id="botaoOfertar" ajax="true" actionListener="#{unitizacaoMB.setCaixaSelecionada(bean)}"
					update=":@form:idPanelConfirmLoginEstoque" oncomplete="confirmacaoLoginEstoque.show()"
					process="@this" immediate="true" image="ui-icon-pencil">
				</p:commandButton>								
			</p:column>
			<p:column sortBy="#{bean.produto.nome}" filterBy="#{bean.produto.nome}">
				<f:facet name="header">#{messages['unitizacao.produto']}</f:facet>
				<h:outputText value="#{bean.produto.nome} "/>
				<h:outputText value="#{bean.categoria.nome}-"/>
				<h:outputText value="#{bean.padrao.nome} #{bean.padrao.valor} -"/>
				<h:outputText value="#{bean.embalagem.nome}-"/>
				<h:outputText value="#{bean.marca.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.paisOrigem.nome}" filterBy="#{bean.paisOrigem.nome}">
				<f:facet name="header">#{messages['unitizacao.pais']}</f:facet>
				<h:outputText value="#{bean.paisOrigem.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.eta}" >
				<f:facet name="header">#{messages['unitizacao.eta']}</f:facet>
				<h:outputText value="#{bean.eta}">
					<f:convertDateTime type="date" pattern="w '-' dd/MM/yyyy"/>
				</h:outputText>
			</p:column>
			<p:column sortBy="#{bean.pallet.quantidade}">
				<f:facet name="header">#{messages['unitizacao.pallet']}</f:facet>
				<h:outputText value="#{bean.pallet.quantidade}"/> - (<h:outputText value="#{bean.quantidade}"/>)
			</p:column>
			<p:column sortBy="#{bean.preco}">
				<f:facet name="header">#{messages['unitizacao.preco']}</f:facet>
				<h:outputText value="#{bean.preco}">
					<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="#

{localeConfig.localidadeMonetaria}"/>
				</h:outputText> - <h:outputText value="#{bean.incoterm.nome}"/>
			</p:column>
			<p:column sortBy="#{bean.armazem.nome}">
				<f:facet name="header">#{messages['unitizacao.armazem']}</f:facet>
				<h:outputText value="#{bean.armazem.nome}"/>
			</p:column>
			<p:column>
				<p:commandLink ajax="true" action="#{unitizacaoMB.setCaixaSelecionada(bean)}" 

update="panelInfoDialogMeuEstoque" oncomplete="infoDialog.show();">
					<h:outputText value="#{messages['unitizacao.info']}"/>
				</p:commandLink>												

	
			</p:column>
			<p:column rendered="#{exibirBotoesAlteracao}">
				<f:facet name="header">#{messages['dataTable.alterar']}</f:facet>
				<p:commandLink id="linkUpdate" action="#{unitizacaoMB.preUpdate}"
						process="@this" immediate="true" update="idToolbar,fieldSetPallet,fieldSetCaixa"
						styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
					<span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
					<span class="ui-button-text">ui-button</span>
					<f:setPropertyActionListener value="#{bean}" target="#{unitizacaoMB.caixaSelecionada}" 

for="linkUpdate"/>
				</p:commandLink>
			</p:column>
			<p:column rendered="#{exibirBotoesAlteracao}">
				<f:facet name="header">#{messages['dataTable.excluir']}</f:facet>
				<p:commandLink id="linkDelete" onclick="confirmacaoDelete.show()" process="@this" immediate="true"
						styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
					<span class="ui-button-icon-primary ui-icon ui-icon-trash"></span>
					<span class="ui-button-text">ui-button</span>
					<f:setPropertyActionListener value="#{bean}" target="#{unitizacaoMB.caixaSelecionada}" 

for="linkDelete"/>
				</p:commandLink>
			</p:column>
		</p:dataTable>
				
		<p:confirmDialog width="400" height="230" message="#{messages['label.confirm.delete']}" showEffect="fade" 

hideEffect="fade"
				header="#{messages['label.dialog.delete']}" severity="alert" widgetVar="confirmacaoDelete" modal="true" 

appendToBody="true">
			<p:commandButton id="botaoConfirmaDeletar" value="#{messages['button.dialog.yes']}" action="#

{unitizacaoMB.deleteCaixa}" 
				immediate="true" ajax="true" update="messages,tabelaUnitizacoes" oncomplete="confirmacaoDelete.hide();">
			</p:commandButton>
			<p:commandButton value="#{messages['button.dialog.no']}" onclick="confirmacaoDelete.hide();"/>	
		</p:confirmDialog>
		
		<ui:include src="../componentes/infoCaixa.xhtml">
			<ui:param name="idPanelInfoCaixa" value="panelInfoDialogMeuEstoque"/>
			<ui:param name="widgetVarDialogInfoCaixa" value="infoDialog" />
			<ui:param name="mbInfoCaixa" value="#{unitizacaoMB}" />				
		</ui:include>
		
		<ui:include src="../componentes/operacaoSolicitarSenha.xhtml">
			<ui:param name="complementoID" value="LoginEstoque"/>
			<ui:param name="mbOperacaoComSenha" value="#{unitizacaoMB}"/>
			<ui:param name="elementosParaAtualizar" value="tabelaUnitizacoes,tabelaUnitizacoesOfertadas"/>
			<ui:param name="acaoConfirmar" value="oferecerCaixa"/>				
		</ui:include>
	</h:form>
</ui:composition>
As always, Thank you so much for your attention.
Igor.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

12 Dec 2011, 01:47

I just recognized the following in your last reply.

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
   xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
   xmlns:ui="http://java.sun.com/jsf/facelets">
The following (below) is recommended in the PF3.0 migration guide (http://wiki.primefaces.org/display/Gene ... ide+to+3.0). Make the following change in all of your xhtml/jsf and let us know what happens, please.

Code: Select all

http://primefaces.prime.com.tr/ui -> http://primefaces.org/ui
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

igcramos
Posts: 4
Joined: 05 Dec 2011, 16:12

12 Dec 2011, 13:29

OK! I'm sorry.

I had opened my projects 2.2.1 and 3.0RC1 at the moment of "copy and paste", but I've copied from the wrong version. The last one, 3.0RC1, only works as you said, changing the namespace. :)

Tks!

development environment: Eclipse Helios, Mojarra 2.0.3 ( b05), Jboss 6.1 SNAPSHOT

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

12 Dec 2011, 18:37

igcramos wrote:The last one, 3.0RC1, only works as you said, changing the namespace. :)

development environment: Eclipse Helios, Mojarra 2.0.3 ( b05), Jboss 6.1 SNAPSHOT
1. Does this mean that you successfully migrated your JSF web app to PrimeFaces 3.0.RC1 (JAR release) and commandLink's are working as designed in your JSF web app, now?
2. Also, does this mean that you changed the namespace as I suggested in my previous response/post?
3. Look for the User control panel in upper right corner of the page, and include your development/test environment details in your signature, so you don't need to type or copy/paste every time you have a question. I need to update mine to 3.0.RC1, since I'm now using the 3.0.RC1 release JAR now. :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests