| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.util; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.*; |
| 18 | |
|
| 19 | |
import java.util.Map; |
| 20 | |
|
| 21 | |
public class SelectModelRenderer implements SelectModelVisitor |
| 22 | |
{ |
| 23 | |
private final MarkupWriter writer; |
| 24 | |
|
| 25 | |
private final ValueEncoder encoder; |
| 26 | |
|
| 27 | |
public SelectModelRenderer(final MarkupWriter writer, ValueEncoder encoder) |
| 28 | 174 | { |
| 29 | 174 | this.writer = writer; |
| 30 | 174 | this.encoder = encoder; |
| 31 | 174 | } |
| 32 | |
|
| 33 | |
public void beginOptionGroup(OptionGroupModel groupModel) |
| 34 | |
{ |
| 35 | 8 | writer.element("optgroup", "label", groupModel.getLabel()); |
| 36 | |
|
| 37 | 8 | writeDisabled(groupModel.isDisabled()); |
| 38 | 8 | writeAttributes(groupModel.getAttributes()); |
| 39 | 8 | } |
| 40 | |
|
| 41 | |
public void endOptionGroup(OptionGroupModel groupModel) |
| 42 | |
{ |
| 43 | 8 | writer.end(); |
| 44 | 8 | } |
| 45 | |
|
| 46 | |
@SuppressWarnings("unchecked") |
| 47 | |
public void option(OptionModel optionModel) |
| 48 | |
{ |
| 49 | 736 | Object optionValue = optionModel.getValue(); |
| 50 | |
|
| 51 | 736 | String clientValue = encoder.toClient(optionValue); |
| 52 | |
|
| 53 | 736 | writer.element("option", "value", clientValue); |
| 54 | |
|
| 55 | 736 | if (isOptionSelected(optionModel, clientValue)) writer.attributes("selected", "selected"); |
| 56 | |
|
| 57 | 736 | writeDisabled(optionModel.isDisabled()); |
| 58 | 736 | writeAttributes(optionModel.getAttributes()); |
| 59 | |
|
| 60 | 736 | writer.write(optionModel.getLabel()); |
| 61 | |
|
| 62 | 736 | writer.end(); |
| 63 | 736 | } |
| 64 | |
|
| 65 | |
private void writeDisabled(boolean disabled) |
| 66 | |
{ |
| 67 | 744 | if (disabled) writer.attributes("disabled", "disabled"); |
| 68 | 744 | } |
| 69 | |
|
| 70 | |
private void writeAttributes(Map<String, String> attributes) |
| 71 | |
{ |
| 72 | 744 | if (attributes == null) return; |
| 73 | |
|
| 74 | 6 | for (Map.Entry<String, String> e : attributes.entrySet()) |
| 75 | 6 | writer.attributes(e.getKey(), e.getValue()); |
| 76 | 6 | } |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
protected boolean isOptionSelected(OptionModel optionModel, String clientValue) |
| 82 | |
{ |
| 83 | 238 | return false; |
| 84 | |
} |
| 85 | |
|
| 86 | |
} |