JSF Mojarra Action Failing

I’m about a week into my JSF Oddjob conversion and I’ve hit my first big frustration. The control panel for a job has buttons for the job actions Run, Stop etc. This all looks like it should be really easy with JSF’s method actions on backing beans so I code it up and press my button and nothing happens.

Many hours later and I’ve narrowed it down to this simple example.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"> 
	<body>
			
		<f:metadata>
		  <f:viewParam name="chosen" value="#{colourBean.colour}"/>
		</f:metadata>
		
		<h1>Pick A Colour</h1>
		<ul>
			<li>
			<h:link value="Orange">
				<f:param name="chosen" value="orange"/>
			</h:link>
			</li>
			<li>
			<h:link value="Green">
				<f:param name="chosen" value="green"/>
			</h:link>
			</li>
		</ul>
	
		<c:if test="#{!empty colourBean.colour}">
			<h:form>
				<h:commandButton value="Confirm #{colourBean.colour}"
					action="#{colourBean.action}" />
			</h:form>
		</c:if>
        	
		<c:if test="#{colourBean.confirmed}">
			<h1>Thank you for choosing #{colourBean.colour}.</h1>
		</c:if>
    </body>
</html>

With the backing bean:

import javax.faces.bean.ManagedBean;

@ManagedBean
public class ColourBean {

	private String colour;
	
	private boolean confirmed;
	
	public void action() {
		confirmed = true;
	}


	public String getColour() {
		return colour;
	}


	public void setColour(String colour) {
		this.colour = colour;
	}


	public boolean getConfirmed() {
		return confirmed;
	}
}

The form gives the choice of two colours. Select one and you’re asked to confirm the choice with a button. Press the button and you get the Thank You message. Simple? You’d think so! I was using Mojarra 2.14, and pressing the button did absolutely nothing. The action method was completely ignored! Almost as an afterthought I thought I’d try MyFaces (also 2.1.4) and voila – it works!

Colour Chooser Working

Colour Chooser Working

Hmm, a bug in Mojarra I thought, so I’m digging about looking for known issues and I come across this little gem in the Known Issues:

This release of Mojarra is not known to work in Apache Tomcat or Jetty. Tomcat and Jetty support will be restored in a future release. It is known to work in Oracle WebLogic and Oracle GlassFish.

And guess what – I’m using Tomcat 7 and hope to deploy on Jetty embedded in Oddjob! – I suspect my issue is actually just a bug, but REALLY not supporting Tomcat and Jetty!!! Looks like it’s MyFaces from now on.

 

Comments are closed.