You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Cedric Hurst <ce...@gmail.com> on 2008/08/24 18:20:03 UTC

commandbutton action not being invoked if form contains programatically-defined selectitems

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.


Re: commandbutton action not being invoked if form contains programatically-defined selectitems

Posted by Cedric Hurst <ce...@gmail.com>.
This is a bit of a delayed response, but I've gotten a couple of emails from
people with a similar issue so I thought I'd post on update on the issue. 
Volker was on the right track in suggesting that it was a validation issue.

In my case, the values for the SelectItems were based on 15-minute
increments of the current system time.  Since the current system time
changes from the point where the form is rendered to the point where the
form is submitted, the JSF validators were throwing an error because the
value is no longer submitted.  If you have a similar sort of issue, I'd
suggest looking for validation errors by including an <h:messages> tag
somewhere in your form.


Volker Weber-5 wrote:
> 
> Hi Cedric,
> 
> 2008/8/24 Cedric Hurst <ce...@gmail.com>:
>>
>> 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 can't find any h:messages tag to show the error messages in you jsf
> sources.
> How could yo be sure there is no conversion/validation error?
> 
> Try adding a h:messages tag somewhere.
> 
> Regards,
>     Volker
> 
>> 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.
>>
>>
> 
> 
> 
> -- 
> inexso - information exchange solutions GmbH
> Bismarckstraße 13 | 26122 Oldenburg
> Tel.: +49 441 4082 356 |
> FAX: +49 441 4082 355 | www.inexso.de
> 
> 

-- 
View this message in context: http://www.nabble.com/commandbutton-action-not-being-invoked-if-form-contains-programatically-defined-selectitems-tp19131952p21963977.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: commandbutton action not being invoked if form contains programatically-defined selectitems

Posted by Volker Weber <v....@inexso.de>.
Hi Cedric,

2008/8/24 Cedric Hurst <ce...@gmail.com>:
>
> 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 can't find any h:messages tag to show the error messages in you jsf sources.
How could yo be sure there is no conversion/validation error?

Try adding a h:messages tag somewhere.

Regards,
    Volker

> 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.
>
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de