Passagem de parametro JSF <f:attribute> com Expression Language

0 respostas
F

Boa noite!!!

Estou iniciando em JSF e desenvolvendo uma aplicação, porém, estou encontrando dificuldades para realizar a passagem de parâmetro utilizando o com EL.

Em uma de minhas paginas, possuo a seguinte dataTable:

<h:dataTable value="#{testeBean.listaProjeto}" var="projeto"  rules="rows" cellpadding="5">
				<f:facet name="caption">Projetos cadastrados</f:facet>
				<h:column>
					<f:facet name="header">Código</f:facet>
					#{projeto.codigo}
				</h:column>
				
				<h:column>
					<f:facet name="header">Descrição</f:facet>
					#{projeto.descricao}
				</h:column>
				
				<h:column>
					<f:facet name="header">Categoria</f:facet>
					#{projeto.categoria}
				</h:column>
				<h:column>
					<f:facet name="header">Status</f:facet>
					#{projeto.status}
				</h:column>
				
				<h:column>
					<h:commandLink action="#{testeBean.detalhes}">
						<h:graphicImage library="imagens" name="editar16.png" style="border:0"/>
						<f:setPropertyActionListener target="#{testeBean.projeto}" value="#{projeto}"/>
					</h:commandLink>
				</h:column>

			</h:dataTable>

Como podem ver, o commandLink action chama o metodo detalhes da classe testeBean, que apenas redireciona para uma pagina que recebe o value "#{projeto}" como parametro, preenchendo os campos da tela. Até aí tudo funciona perfeitamente, o problema é que essa ultima tela chamada, além dos campos preenchidos automaticamente (referente ao objeto projeto), preciso informar outros campos que são referentes a outro objeto (proposta), que por sua vez, entre outros atributos, possui o atributo projeto. Então criei a tela de interface da seguinte maneira:

<h:form id="detalhes">
			<h:messages/>
			<h:inputHidden value="#{testeBean.projeto.codigo}"/>
			<h:inputHidden value="#{testeBean.projeto.status}"/>
			<h:inputHidden value="#{testeBean.destinoSalvar}"/>

			<h:panelGrid columns="2">
				<h:outputLabel value="Descrição:" for="descricao"/>
				<h:inputText id="descricao" label="Descrição:" value="#{testeBean.projeto.descricao}" size="30" maxlength="30" required="true" disabled="true">
					<f:validateLength minimum="5" maximum="30"/>
				</h:inputText>
				
				<h:outputLabel value="Detalhes:" for="detalhes"/>
				<h:inputTextarea id="detalhes" label="Detalhes:" value="#{testeBean.projeto.detalhes}" size="500" maxlength="500" required="true" disabled="true">
					<f:validateLength minimum="10" maximum="500"/>
				</h:inputTextarea>
				
				<h:outputLabel value="Categoria:" for="categoria"/>
    			<h:selectOneMenu id="categoria" value="#{testeBean.projeto.categoria}" disabled="true">
			       <f:selectItem itemValue="desenvSis" itemLabel="Desenvolvimento de Sistemas"/>
			       <f:selectItem itemValue="webDesign" itemLabel="Web Design"/>
				</h:selectOneMenu>
       			
       			<h:outputLabel value="Receber propostas até:" for="dtLimiteProposta"/>
				<h:inputText id="dtLimiteProposta" label="Receber propostas até:" value="#{testeBean.projeto.dtLimiteProposta}" size="10" maxlength="10" required="false" disabled="true">
					<f:convertDateTime dateStyle="medium"/>
				</h:inputText>
				
				<h:outputLabel value="Orçamento:" for="orcamento"/>
				<h:inputText id="orcamento" label="Orçamento:" value="#{testeBean.projeto.orcamento}" size="30" maxlength="30" required="false" disabled="true">
				</h:inputText>
				
				<h:outputLabel value="Data de Entrega:" for="dtEntrega"/>
				<h:inputText id="dtEntrega" label="Entregar em:" value="#{testeBean.projeto.dtEntrega}" size="10" maxlength="10" required="false" disabled="true">
					<f:convertDateTime dateStyle="medium"/>
				</h:inputText>
			</h:panelGrid>
		</h:form>
		<h:form id="proposta">
		<h:inputHidden value="#{projeto}"/>
			<h:messages/>
		
			<h:panelGrid columns="2">
				<h:outputLabel value="Orçamento ofertado:" for="orcamentoOfertado"/>
				<h:inputText id="orcamentoOfertado" label="Orçamento ofertado:" value="#{testeBean.proposta.orcamentoOfertado}" size="30" maxlength="30" required="false">
				</h:inputText>
				
				<h:outputLabel value="Data de Entrega Ofertada:" for="dtEntregaOfertada"/>
				<h:inputText id="dtEntregaOfertada" label="Data de Entrega Ofertada:" value="#{testeBean.proposta.dtEntregaOfertada}" size="10" maxlength="10" required="false">
					<f:convertDateTime dateStyle="medium"/>
				</h:inputText>
				
				<h:outputLabel value="Detalhes:" for="detalhes"/>
				<h:inputTextarea id="detalhes" label="Detalhes:" value="#{testeBean.proposta.detalhes}" size="500" maxlength="500" required="true">
					<f:validateLength minimum="10" maximum="500"/>
				</h:inputTextarea>
				
				#{testeBean.projeto.codigo}
				<h:commandButton value="Salvar" actionListener="#{testeBean.salvarProposta}">
					<f:attribute name="attributeName1" value="teste" />
        			<f:attribute name="attributeName2" value="#{testeBean.projeto.codigo}" />
				</h:commandButton>
			</h:panelGrid>
		</h:form>

E o metodo salvarProposta:

public String salvarProposta(ActionEvent event) {
		ContextoBean contextobean = null;
		contextobean = ContextoUtil.getContextoBean();
		this.proposta.setUsuario(contextobean.getUsuarioLogado());
//		this.proposta.setProjeto(FacesUtil.getActionAttribute(event, "attributeName1"));
		PropostaRN propostaRN = new PropostaRN();
		propostaRN.salvar(this.proposta);
		 	String attributeName1 = FacesUtil.getActionAttribute(event, "attributeName1");
	        String attributeName2 = FacesUtil.getActionAttribute(event, "attributeName2");
	        System.out.println("attributeName1: " + attributeName1);
	        System.out.println("attributeName2: " + attributeName2);
		return this.destinoSalvar = "/desenvolvedor/projetos";
	}

Bom, como podem ver, nem terminei o setProjeto, pois, nem mesmo o teste funcionou. O System.out do attributeName1 aparece normalmente, já o da EL "#{testeBean.projeto.descricao}" nao, sempre recebo null para esse parametro. Com isso, nao consigo salvar meu objeto proposta setando o atributo projeto.

Desculpem se o post ficou muito grande.

Obrigado.

Criado 22 de setembro de 2011
Respostas 0
Participantes 1