Tapestry: default value for dropdown component

I use the following code for select-component:

Java class:

@Component(parameters = {"blankOption=AUTO", "model=someModel", "value=someId", "zone=someZone"}) private Select demoSelect; 

Template:

 <select t:id="demoSelect" /> 

It will display something like this:

 <select id="demoSelect" name="demoSelect"> <option value=""></option> <option value="1">first</option> <option value="2">second</option> <option value="3">third</option> </select> 

The behavior I'm looking for is that a certain parameter is defined (this should be defined in the page class). How can I configure this in Tapestry? Basically I need to tell Tapestry to display "selected" for the corresponding option, for example:

 <select id="demoSelect" name="demoSelect"> <option value=""></option> <option value="1">first</option> <option value="2" selected="selected">second</option> <option value="3">third</option> </select> 

Is it enough to change the model (I don’t think so), or do I need to expand the Select component itself. I found this article that looked pretty promising, but unfortunately all the links to the source codes are dead.

+4
source share
2 answers

There is no need to expand anything. Just setting the property to a value before rendering does the trick:

 @Property private SomeType someId; @SetupRender void initSomeId() { if (this.someId == null) { this.someId = this.getDefaultValueForSomeId(); } } 
+6
source

Another easy way to fix this is if you want it to use the first parameter automatically by default, you can change blankOption="AUTO" to blankOption="NEVER" .

This will remove the sometimes unnecessary initial empty space (Tapestry function) of the drop-down list. It is useful to ensure that the user cannot just leave the selection empty and free up exception handling.

+1
source

All Articles