Dúvida MyFaces

8 respostas
andre_guitar7

Gente, não sei se alguém usa MyFaces aqui mas estou precisando de uma ajuda, estou desde semana passada não entendendo o que está acontecendo..
Tenho um formulário dessa forma:

<%@include file="inc/taglibs.inc" %>
<%@include file="inc/header.inc" %>

<f:view>
	<h:outputText value="Criar Login" /><t:htmlTag value="br" /><t:htmlTag value="br" />
	<h:form>
		<table border="1">
			<tr>
				<td>
					<h:outputText value="Nome: " />
				</td>
				<td>		
					<h:inputText id="name" size="25" value="#{PersonAction.name}" />
				</td>
			</tr>
			<tr>
				<td>
					<h:outputText value="Login:" />
				</td>
				<td>
					<h:inputText id="login" size="15" value="#{PersonAction.login}" />
				</td>
			</tr>
			<tr>
				<td>
					<h:outputText value="Senha: " />
				</td>
				<td>
					<h:inputSecret id="password" size="15" value="#{PersonAction.password}" />
				</td>
			</tr>
			<tr>
				<td colspan="2" align="right">
					<h:commandButton value="Gravar" id="insert" action="#{PersonAction.insert}" />
				</td>
			</tr>
		</table>
	</h:form>
</f:view>

<%@include file="inc/footer.inc" %>
Meu faces-config dessa forma:
<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>

	<managed-bean>
      	<managed-bean-name>PersonAction</managed-bean-name>
      	<managed-bean-class>br.comunidadebetel.web.action.PersonAction</managed-bean-class>
      	<managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    
	<navigation-rule>	
		<navigation-case>
			<from-outcome>personInsered</from-outcome>
			<to-view-id>/personInsered.jsp</to-view-id>
		</navigation-case>	
	</navigation-rule>
	
</faces-config>
E meu managed bean assim:
package br.comunidadebetel.web.action;

import br.comunidadebetel.bean.human.Person;
import br.comunidadebetel.exception.BeanDuplicateException;
import br.comunidadebetel.model.PersonManager;

public class PersonAction extends Person {
	
	private final static String PERSON_INSERED = "personInsered";
	
	public String insert(){
		try {
			Person person = new Person();
			person.setName( this.getName() );
			person.setLogin( this.getLogin() );
			person.setPassword( this.getPassword() );
			PersonManager.insert( person );
		}catch( BeanDuplicateException e ){
			
		}
		return PERSON_INSERED;
	}

}
Eu clico no botão da minha página web mas ele vai pra mesma página e não faz ação nenhuma.. não estou entendendo, será que tem algo errado?

vlews

8 Respostas

urubatan

primeiro, um MBean não é uma action do struts, mudar o nome vai facilitar eixar as coisas separadas …

segundo,
Person tem os atributos que tu ta tentando setar com os inputText?

se tem, tenta colocar na página em qualquer lugar dentro do form, um:
<h:messages globalOnly=“false”/>

e testa novamente :smiley:

andre_guitar7

Ufa, valew… pensei que era difícil encontrar alguém que saiba MyFaces…

Eu nunca usei o Struts… se ele não é um action o que seria então?

urubatan

ele é um bean gerenciado, como diz o nome …
só isto …

só que os botões do JSF tem a possibilidade de chamar um método de um ben gerenciado …

andre_guitar7
urubatan:
primeiro, um MBean não é uma action do struts, mudar o nome vai facilitar eixar as coisas separadas ...

segundo,
Person tem os atributos que tu ta tentando setar com os inputText?

se tem, tenta colocar na página em qualquer lugar dentro do form, um:
<h:messages globalOnly="false"/>

e testa novamente :D


Fiz o teste dá o mesmo problema, ele chama a mesma página e nem faz cócegas nas ações da classe PersonAction...

<%@include file="inc/taglibs.inc" %>
<%@include file="inc/header.inc" %>

<f:view>
	<h:outputText value="Criar Login" /><t:htmlTag value="br" /><t:htmlTag value="br" />
	<h:form>
		<h:messages globalOnly="false"/> 
		<table border="1">
			<tr>
				<td>
					<h:outputText value="Nome: " />
				</td>
				<td>		
					<h:inputText id="name" size="25" value="#{PersonAction.name}" />
				</td>
			</tr>
			<tr>
				<td>
					<h:outputText value="Login: " />
				</td>
				<td>
					<h:inputText id="login" size="15" value="#{PersonAction.login}" />
				</td>
			</tr>
			<tr>
				<td>
					<h:outputText value="Senha: " />
				</td>
				<td>
					<h:inputSecret id="password" size="15" value="#{PersonAction.password}" />
				</td>
			</tr>
			<tr>
				<td colspan="2" align="right">
					<h:commandButton value="Gravar" id="insert" action="#{PersonAction.insert}" />
				</td>
			</tr>
		</table>
	</h:form>
</f:view>

<%@include file="inc/footer.inc" %>
urubatan

apareceu alguma mensagem de erro na tela quando tu clicou no botão?
alguma mensagem de erro no log do teu app server?

andre_guitar7

Meu log:

15/08/2006 16:47:54 org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Arquivos de programas\Java\jdk1.6.0\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;;C:\arquiv~1\Java\jdk1.6.0\bin;%CVS_HOME% 15/08/2006 16:47:55 org.apache.coyote.http11.Http11BaseProtocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 15/08/2006 16:47:55 org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1594 ms 15/08/2006 16:47:55 org.apache.catalina.core.StandardService start INFO: Starting service Catalina 15/08/2006 16:47:55 org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/5.5.17 15/08/2006 16:47:55 org.apache.catalina.core.StandardHost start INFO: XML validation disabled 2006-08-15 16:47:57,343 INFO myfaces.config.FacesConfigurator -> Reading standard config org/apache/myfaces/resource/standard-faces-config.xml 2006-08-15 16:47:58,156 INFO myfaces.config.FacesConfigurator -> Reading config jar:file:/D:/Andre/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/comunidadebetel/WEB-INF/lib/tomahawk-1.1.5-SNAPSHOT.jar!/META-INF/faces-config.xml 2006-08-15 16:47:58,328 INFO myfaces.config.FacesConfigurator -> Reading config /WEB-INF/faces-config.xml 2006-08-15 16:47:58,500 WARN shared_impl.util.LocaleUtils -> Locale name in faces-config.xml null or empty, setting locale to default locale : pt_BR 2006-08-15 16:47:59,718 INFO myfaces.webapp.StartupServletContextListener -> ServletContext 'D:\Andre\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\comunidadebetel Não aparece nenhuma mensagem de erro, ele simplismente retorna a mesma página, com o formulário em branco... initialized. 2006-08-15 16:47:59,734 INFO myfaces.webapp.StartupServletContextListener -> Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory 15/08/2006 16:48:00 org.apache.coyote.http11.Http11BaseProtocol start INFO: Starting Coyote HTTP/1.1 on http-8080 15/08/2006 16:48:01 org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009 15/08/2006 16:48:01 org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/203 config=null 15/08/2006 16:48:01 org.apache.catalina.storeconfig.StoreLoader load INFO: Find registry server-registry.xml at classpath resource 15/08/2006 16:48:01 org.apache.catalina.startup.Catalina start INFO: Server startup in 6329 ms 2006-08-15 16:48:08,796 INFO [Catalina].[localhost].[/comunidadebetel] -> No state saving method defined, assuming default server state saving 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.PRETTY_HTML' found, using default value true 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.ALLOW_JAVASCRIPT' found, using default value true 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.DETECT_JAVASCRIPT' found, using default value false 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.AUTO_SCROLL' found, using default value false 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.ADD_RESOURCE_CLASS' found, using default value org.apache.myfaces.renderkit.html.util.DefaultAddResource 2006-08-15 16:48:09,750 INFO shared_impl.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.CHECK_EXTENSIONS_FILTER' found, using default value true 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.PRETTY_HTML' found, using default value true 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.ALLOW_JAVASCRIPT' found, using default value true 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.DETECT_JAVASCRIPT' found, using default value false 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.AUTO_SCROLL' found, using default value false 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.ADD_RESOURCE_CLASS' found, using default value org.apache.myfaces.renderkit.html.util.DefaultAddResource 2006-08-15 16:48:09,828 INFO shared_tomahawk.config.MyfacesConfig -> No context init parameter 'org.apache.myfaces.CHECK_EXTENSIONS_FILTER' found, using default value true
Não aparece nenhuma mensagem de erro, ele simplismente retorna a mesma página, com o formulário em branco…

andre_guitar7

Alguém manja??? :frowning:

andre_guitar7

Descobri!!!

Eu fiz um taglib.inc aonde estão todos os meus tag libs e incluo nas minhas páginas jsp´s usando o <%@include file=“inc/taglibs.inc” %>. Se eu tiro esse include e coloco diretamente nas páginas:

<%@ page language="java" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
Ele funciona… mas pq o include não funciona???

Criado 15 de agosto de 2006
Ultima resposta 15 de ago. de 2006
Respostas 8
Participantes 2