myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cedric Hurst <cedric.hu...@gmail.com>
Subject commandbutton action not being invoked if form contains programatically-defined selectitems
Date Sun, 24 Aug 2008 16:20:03 GMT

I have an <h:form> which contains two <h:selectOneMenu> elements.  These
elements are being populated programatically with a <f:selectItems> tied to
a JSF managed bean which returns List<SelectItem>.  Unfortunately, when I
attempt to click the <h:commandButton> to invoke an action, the action does
not get processed.  I receive no error message, it just fails silently.  If
I remove the <h:selectOneMenu> elements from the code, the action is
processed fine.  Here are some code snippets:

JSP Code for the Form:

<h:form id="status">
	<p>Today, I'm working at
		<h:selectOneMenu value="#{event.placeId}">
			<f:selectItem itemLabel="-- Select a location --" />
			<f:selectItems value="#{place.placeOptions}"/>
		</h:selectOneMenu>
		 from 
		 
		 <h:selectOneMenu id="startTime" value="#{event.start}">
		 	<f:selectItems value="#{event.possibleStartTimes}"/>
		 </h:selectOneMenu>
		 to 
		  <h:selectOneMenu id="endTime" value="#{event.finish}">
		 	<f:selectItems value="#{event.possibleFinishTimes}"/>
		 </h:selectOneMenu>
		 
		<h:commandButton action="#{event.createEventAction}" value="Mowork"/>
	</p>
</h:form>

Managed Bean methods to Populate Menu Items:

private List<SelectItem> selectItemsFromTimeRange(Calendar begin, Calendar
end)
{
	List<SelectItem> items = new ArrayList<SelectItem>();
	
	while(begin.compareTo(end) < 0)
	{
		items.add(new SelectItem(
			new Long(begin.getTimeInMillis()).toString(),
			timeFormat.format(begin.getTime())
		));
		
		begin.add(Calendar.MINUTE, 15);
	}
	
	return items;
}

public List<SelectItem> getPossibleStartTimes()
{
	Calendar time =
Calendar.getInstance(TimeZone.getTimeZone("America/Chicago"));
	
	List<SelectItem> items = new ArrayList<SelectItem>();
	
	items.add(new SelectItem(
		timeFormat.format(time.getTime()),
		"Right Now"
	));
	
	Calendar begin = (Calendar)time.clone();
	begin.add(Calendar.MINUTE, 1);
	if(begin.get(Calendar.MINUTE)%15 != 0)
		begin.add(Calendar.MINUTE, 15-(begin.get(Calendar.MINUTE)%15));
	
	Calendar end = (Calendar)begin.clone();
	end.add(Calendar.HOUR, 24);
	
	items.addAll(selectItemsFromTimeRange(begin, end));
	
	return items;
}

public List<SelectItem> getPossibleFinishTimes()
{
	Calendar begin =
Calendar.getInstance(TimeZone.getTimeZone("America/Chicago"));
	begin.add(Calendar.MINUTE, 15);
	if(begin.get(Calendar.MINUTE)%15 != 0)
		begin.add(Calendar.MINUTE, 15-(begin.get(Calendar.MINUTE)%15));
	
	Calendar end = (Calendar)begin.clone();
	end.add(Calendar.HOUR, 24);
	
	return selectItemsFromTimeRange(begin, end);
}

Managed Bean method to Process Action:

public String createEventAction()
{
	System.out.println("create event action is running");
	return "createEventSuccess";
}

The full codebase for working and non-working versions can also be found
here:

http://trac.assembla.com/moworking/browser/branches/CreateEventActionWorkingWithNoSelectItems?rev=63

http://trac.assembla.com/moworking/browser/branches/CreateEventActionNotWorkingWithSelectItems?rev=65

Please let me know if you have any suggestions.

Environment
===
MyFaces Core 1.2.3
MyFaces Tomahawk 1.1.6
Apache Geronimo 2.1.2 (Tomcat)
Java HotSpot 1.5.0 64-bit Server VM
Apple Mac OS X 10.5 (Leopard)
Thanks,
- C
-- 
View this message in context: http://www.nabble.com/commandbutton-action-not-being-invoked-if-form-contains-programatically-defined-selectitems-tp19131952p19131952.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message