#{extends '../../main.html'/}# #{set title:'Html Reference'/}# #{set tab:'management'/}# #{renderTagArgs '../docHome.html'/}#

Pulldown Menu

When doing a Pulldown Menu, you generally want to feed a List of things and the currently selected item to the page as we do here:

#{form action:@[POST_ENUM_LIST_SINGLE_SELECT]@, class:'form-horizontal'}# #{field 'selectedColor', label:'Color'}# #{/field}# #{/form}#

The webpieces html code above is:

*[#{form action:@[POST_ENUM_LIST_SINGLE_SELECT]@, class:'form-horizontal'}#

	#{field 'selectedColor', label:'Color'}#
		
	#{/field}#
  
  

#{/form}#]*

Enums have a special webconverter you need to install and the code for that is:

*[	public static class WebConverter implements ObjectStringConverter {

	    public String objectToString( ColorEnum value ) {
	        if ( value == null ) {
	            return null;
	        }

	        return value.getDatabaseCode();
	    }

	    public ColorEnum stringToObject( String value ) {
	        if ( value == null ) {
	            return null;
	        }

	        return ColorEnum.lookupByCode( value );
	    }

		@Override
		public Class getConverterType() {
			return ColorEnum.class;
		}
	}]*

Of course, you need to install the converter from one of your GuiceModules. Once down, it converts for html pages, cookies(which are string based) or any string to enum conversion needed. Here is that code:

*[Multibinder conversionBinder = Multibinder.newSetBinder(binder, ObjectStringConverter.class);
conversionBinder.addBinding().to(ColorEnum.WebConverter.class);]*

The webpieces routes for the above is:

*[scopedBldr.addRoute(BOTH, HttpMethod.GET , "/examples/enumList", "ExamplesController.enumList", ExampleRouteId.ENUM_LIST_SINGLE_SELECT);
scopedBldr.addRoute(BOTH, HttpMethod.POST, "/examples/postEnumList", "ExamplesController.postEnumList", ExampleRouteId.POST_ENUM_LIST_SINGLE_SELECT);
scopedBldr.addRoute(BOTH, HttpMethod.GET , "/examples/enumListResult", "ExamplesController.enumListResult", ExampleRouteId.ENUM_LIST_SINGLE_SELECT_RESULT);]*

The Controller GET and POST methods for this page is:

*[	public Render enumList() {
		List colorList = Arrays.asList(ColorEnum.values());
		
		return Actions.renderThis(
				"menu", menuCreator.getMenu(),
				"colors", colorList,
				"selectedColor", ColorEnum.GREEN
				);
	}
	
	public Redirect postEnumList(String selectedColor) {
		//We could put the firstName in the url such as /examples/inputResult/{firstName} 
		//or we could save to database
		//or we can put it in flash and for this example, we put it in flash
		Current.flash().put("selectedColor", selectedColor);
		Current.flash().keep();
		return Actions.redirect(ExampleRouteId.ENUM_LIST_SINGLE_SELECT_RESULT);
	}]*