[Resolvido] Alterar dados e Excluir naum funciona mais

6 respostas
Kleber-rr

Ola pessoal, estou com um problema por causa de uma migraçao que fiz de JSP para XHTML.

O problema é na ActionListener de Alterar e Excluir, que com o jsf funcionavam, agora naum funcionam mais...

os métodos
public String excluir(ActionEvent event) {
		System.out.println("Excluindo: " + perguntas.getCod_perguntas());
		UIComponent link = event.getComponent();
		UIParameter param = (UIParameter) link.findComponent("excluir");
		Long id = (Long) param.getValue();

		Session session = HibernateUtil.currentSession();
		Dao<Perguntas> perguntasDao = new Dao<Perguntas>(session,
				Perguntas.class);
		this.perguntas = perguntasDao.load(id);
		perguntasDao.delete(this.perguntas);
		this.perguntas = new Perguntas();
		return "excluido";

	}

	public void escolhePerguntas(ActionEvent event) {
		UIComponent link = event.getComponent();
		UIParameter param = (UIParameter) link.findComponent("editCod");
		Long id = (Long) param.getValue();

		Session session = HibernateUtil.currentSession();
		Dao<Perguntas> dao = new Dao<Perguntas>(session, Perguntas.class);
		this.perguntas = dao.load(id);
	}
O XHTML da pergunta:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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: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">
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    	<link rel="StyleSheet" type="text/css" href="/style/style.css" media="screen" />
 </head>

<ui:composition template="/pages/template/template.xhtml">
    	<ui:define name="corpo">
<body>
    	<f:view> 
		<h:form>
			<h:panelGrid>
			
		<h:outputText value="Descrição:  " />
		
		<h:inputText value="#{perguntasHandler.perguntas.descricao}" required="true" validator="#{perguntasHandler.validaCase}">
			<f:validateLength minimum="5" />
		</h:inputText>
		
		<h:outputText value="Tipo:  " />
		
		<h:inputText value="#{perguntasHandler.perguntas.tipo}" required="true" validator="#{perguntasHandler.validaCase}">
			<f:validateLength minimum="2" />
		</h:inputText>
		
		
		<h:commandButton value="Salvar" action="#{perguntasHandler.salva}" />


	<rich:spacer height="10"/>
	<rich:separator height="1" lineType="dotted"/>
	<rich:spacer height="10"/>

	<ui:include src="listaperguntas.xhtml" />

	</h:panelGrid>
	</h:form>
	
	</f:view>
</body>
	</ui:define>
	</ui:composition>

</html>
O XHTML da listapergunta que tem as chamadas alterar e excluir:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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: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">
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
 </head>
<body>
<f:subview id="listaperguntas">
	<h:form>
		<rich:dataTable value="#{perguntasHandler.listaPerguntas}" var="f" rendered="#{not empty perguntasHandler.listaPerguntas}" rows="5" id="perguntas">
		<h:column>
			<f:facet name="header">
				<h:outputText value="Código"/>
			</f:facet>
				<h:outputText value="#{f.cod_perguntas}"/>
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Descrição"/>
			</f:facet>
				<h:outputText value="#{f.descricao}"/>		
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Tipo"/>
			</f:facet>
				<h:outputText value="#{f.tipo}"/>		
		</h:column>
		

		<h:column>
			<f:facet name="header">
				<h:outputText value="Alterar"/>
			</f:facet>
			
			<h:commandButton value="Alterar" actionListener="#{perguntasHandler.escolhePerguntas}">
				<f:param id="editCod" name="cod_perguntas" value="#{f.cod_perguntas}"/>
			</h:commandButton>
			
		</h:column>

		<h:column>
			<f:facet name="header">
				<h:outputText value="Excluir"/>
			</f:facet>
			<h:commandButton value="Excluir" actionListener="#{perguntasHandler.excluir}" />
			<f:param id="excluir" name="cod_perguntas" value="#{f.cod_perguntas}"/>
		</h:column>
		

		<f:facet name="footer">
			<rich:datascroller/>
		</f:facet>
		
		</rich:dataTable>
	
	
	</h:form>
</f:subview>
</body>
</html>

A diferença básica foi o include da listapergunta.xhtml na pergunta.xhtml:

era assim:
<f:include page="listaperguntas.xhtml" />
ficou assim:
	<ui:include src="listaperguntas.xhtml" />
se eu deixar da primeira forma, me dá esse erro na hora de abrir a pagina:
An Error Occurred:
/pages/questionario/perguntas.xhtml @41,43 <f:include> Tag Library supports namespace: http://java.sun.com/jsf/core, but no tag was defined for name: include

Eae galera, alguma sugestão??

6 Respostas

Kleber-rr

Ah sim, e no console me aparece essa mensagem:

28/01/2010 12:33:03 com.sun.faces.lifecycle.RenderResponsePhase execute INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed. sourceId=j_id42:j_id47[severity=(ERROR 2), summary=(Campo Obrigatorio.), detail=(Campo Obrigatorio.)] sourceId=j_id42:j_id45[severity=(ERROR 2), summary=(Campo Obrigatorio.), detail=(Campo Obrigatorio.)]

Fierodd

A mensagem diz que não existe a tag include dentro da taglib que vc chamou de f: (java.sun.com/jsf/core)
a tag include se existir deve estar em outra taglib

Kleber-rr

Fierodd:
A mensagem diz que não existe a tag include dentro da taglib que vc chamou de f: (java.sun.com/jsf/core)
a tag include se existir deve estar em outra taglib

O problema amigo, é que quando eu usava a pagina em JSP, naum usava o Facelets, essa tag funcionava perfeitamente…

E agora?

Fierodd

Quando vc usava jsp a taglib f: apontava para esse mesmo namespace (java.sun.com/jsf/core)?
Dá uma conferida ai pq na documentação não há essa tag include

Link da documentação das tags: http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/tlddocs/index.html

Kleber-rr
Fierodd:
Quando vc usava jsp a taglib f: apontava para esse mesmo namespace (java.sun.com/jsf/core)? Dá uma conferida ai pq na documentação não há essa tag include

Link da documentação das tags: http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/tlddocs/index.html


Mano, na verdade estava jsp:include, olha como estam as taglibs na jsp:

&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%&gt;
&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%&gt;
&lt;%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %&gt;
&lt;%@ taglib uri="http://richfaces.org/rich" prefix="rich" %&gt;
//... 
	&lt;jsp:include page="listaperguntas.jsp" /&gt;
Tive que mudar de jsp para xhtml para poder usar o Facelets, e ficou assim:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;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"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"&gt;

// que  o jsp:include não funciona...
	&lt;jsp:include page="listaperguntas.xhtml" /&gt; //unknown tag jsp:include

Precipitaçao minha. Falei que era f:include e era jsp:include. Perdão amigo.

Mas continuo com o problema. O q devo fazer?? Se eu usar:
&lt;ui:include src="listaperguntas.xhtml" /&gt;

Não funciona... :(

Kleber-rr

Resolvido pessoal!!! O problema é q eu tinha um objeto required=“true” e ficava dando erro quando eu ia alterar ou excluir o objeto.

Flws.

Criado 28 de janeiro de 2010
Ultima resposta 29 de jan. de 2010
Respostas 6
Participantes 2