You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "gioacchinomauri@libero.it" <gi...@libero.it> on 2006/06/14 21:21:01 UTC

h:commandButton and actionListener

Hi all,
I've resolved the problem of some time ago (different versions of myfaces deployed on tomcat :( ) but now i've a new problem about h:commandButton and actionListener associated on it.

When i click on the button the actionListener is (correctly) fired but the same behaviour (after the first time i click the button) is fired when i click on the "refresh" button of my web browser. Is there a way to fire the actionListener only on when i click on the h:commandButton ?

I'm using the latest myfaces implementation of JSF on Tomcat 5.5.17. The same problem arise on FireFox 1.5 and Internet Explorer 6.

Thanks for all the help

This is my (very) simple jsp page:
**************************
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

	<title>My JSF 'index.jsp' starting page</title>
</head>
  
<body>
	<f:view>
		<h:form>
		hello world
		<br>
		<h:commandButton value="click me" action="none" >
			<f:actionListener type="it.hostingjava.MyListener" />
		</h:commandButton>
		
		</h:form>
		<br>		
	</f:view>
</body>
</html>
**********************************

And here is the ultra-simple Listener:
*********************************
package it.hostingjava;

import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

public class MyListener implements ActionListener {

	public void processAction(ActionEvent arg0) throws AbortProcessingException {
		System.out.println("MyListener.processAction");
	}

}

***************************************

Here is the rendered HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

	<title>My JSF 'index.jsp' starting page</title>
</head>
  
<body>
	
		<form id="_idJsp0" name="_idJsp0" method="post" action="/myjsf/index.faces" enctype="application/x-www-form-urlencoded">
		hello world
		<br>
		
			
		<input id="_idJsp0:_idJsp1" name="_idJsp0:_idJsp1" type="submit" value="click me" onclick="clear__5FidJsp0();" />
		
		<input type="hidden" name="_idJsp0_SUBMIT" value="1" /><input type="hidden" name="jsf_sequence" value="11" /><input type="hidden" name="_idJsp0:_link_hidden_" /><script type="text/javascript"><!--
function clear__5FidJsp0() {
  var f = document.forms['_idJsp0'];
  f.elements['_idJsp0:_link_hidden_'].value='';
  f.target='';
}
clear__5FidJsp0();
//--></script></form>
		<br>		
	
<!-- MYFACES JAVASCRIPT -->

</body>
</html>

******************************************************