| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.corelib.internal; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.ComponentAction; |
| 18 | |
import org.apache.tapestry5.ComponentResources; |
| 19 | |
import org.apache.tapestry5.Field; |
| 20 | |
import org.apache.tapestry5.ioc.Locatable; |
| 21 | |
import org.apache.tapestry5.ioc.Location; |
| 22 | |
import org.apache.tapestry5.ioc.internal.util.CollectionFactory; |
| 23 | |
import org.apache.tapestry5.ioc.internal.util.Defense; |
| 24 | |
import org.apache.tapestry5.ioc.internal.util.IdAllocator; |
| 25 | |
import org.apache.tapestry5.services.ClientBehaviorSupport; |
| 26 | |
|
| 27 | |
import java.util.List; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public class FormSupportImpl implements InternalFormSupport, Locatable |
| 36 | |
{ |
| 37 | |
private final ComponentResources resources; |
| 38 | |
|
| 39 | |
private final ClientBehaviorSupport clientBehaviorSupport; |
| 40 | |
|
| 41 | |
private final boolean clientValidationEnabled; |
| 42 | |
|
| 43 | |
private final IdAllocator idAllocator; |
| 44 | |
|
| 45 | |
private final String clientId; |
| 46 | |
|
| 47 | |
private final ComponentActionSink actionSink; |
| 48 | |
|
| 49 | |
private final String formValidationId; |
| 50 | |
|
| 51 | |
private List<Runnable> commands; |
| 52 | |
|
| 53 | |
private String encodingType; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public FormSupportImpl(ComponentResources resources, String formValidationId) |
| 59 | |
{ |
| 60 | 180 | this(resources, null, null, null, false, null, formValidationId); |
| 61 | 180 | } |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public FormSupportImpl(ComponentResources resources, String clientId, ComponentActionSink actionSink, |
| 67 | |
ClientBehaviorSupport clientBehaviorSupport, |
| 68 | |
boolean clientValidationEnabled, IdAllocator idAllocator, String formValidationId) |
| 69 | 542 | { |
| 70 | 542 | this.resources = resources; |
| 71 | 542 | this.clientId = clientId; |
| 72 | 542 | this.actionSink = actionSink; |
| 73 | 542 | this.clientBehaviorSupport = clientBehaviorSupport; |
| 74 | 542 | this.clientValidationEnabled = clientValidationEnabled; |
| 75 | 542 | this.idAllocator = idAllocator; |
| 76 | 542 | this.formValidationId = formValidationId; |
| 77 | 542 | } |
| 78 | |
|
| 79 | |
public Location getLocation() |
| 80 | |
{ |
| 81 | 2 | return resources.getLocation(); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public String getFormComponentId() |
| 85 | |
{ |
| 86 | 6 | return resources.getCompleteId(); |
| 87 | |
} |
| 88 | |
|
| 89 | |
public String allocateControlName(String id) |
| 90 | |
{ |
| 91 | 952 | return idAllocator.allocateId(id); |
| 92 | |
} |
| 93 | |
|
| 94 | |
public <T> void store(T component, ComponentAction<T> action) |
| 95 | |
{ |
| 96 | 2126 | actionSink.store(component, action); |
| 97 | 2126 | } |
| 98 | |
|
| 99 | |
public <T> void storeAndExecute(T component, ComponentAction<T> action) |
| 100 | |
{ |
| 101 | 1624 | actionSink.store(component, action); |
| 102 | |
|
| 103 | 1624 | action.execute(component); |
| 104 | 1624 | } |
| 105 | |
|
| 106 | |
public void defer(Runnable command) |
| 107 | |
{ |
| 108 | 26 | if (commands == null) commands = CollectionFactory.newList(); |
| 109 | |
|
| 110 | 26 | commands.add(Defense.notNull(command, "command")); |
| 111 | 26 | } |
| 112 | |
|
| 113 | |
public void executeDeferred() |
| 114 | |
{ |
| 115 | 530 | if (commands == null) return; |
| 116 | |
|
| 117 | 22 | for (Runnable r : commands) |
| 118 | 26 | r.run(); |
| 119 | |
|
| 120 | 22 | commands.clear(); |
| 121 | 22 | } |
| 122 | |
|
| 123 | |
public String getClientId() |
| 124 | |
{ |
| 125 | 26 | return clientId; |
| 126 | |
} |
| 127 | |
|
| 128 | |
public String getEncodingType() |
| 129 | |
{ |
| 130 | 358 | return encodingType; |
| 131 | |
} |
| 132 | |
|
| 133 | |
public void setEncodingType(String encodingType) |
| 134 | |
{ |
| 135 | 12 | Defense.notBlank(encodingType, "encodingType"); |
| 136 | |
|
| 137 | 12 | if (this.encodingType != null && !this.encodingType.equals(encodingType)) |
| 138 | 2 | throw new IllegalStateException(InternalMessages.conflictingEncodingType(this.encodingType, encodingType)); |
| 139 | |
|
| 140 | 10 | this.encodingType = encodingType; |
| 141 | 10 | } |
| 142 | |
|
| 143 | |
public void addValidation(Field field, String validationName, String message, Object constraint) |
| 144 | |
{ |
| 145 | 678 | if (clientValidationEnabled) |
| 146 | 476 | clientBehaviorSupport.addValidation(field, validationName, message, constraint); |
| 147 | 678 | } |
| 148 | |
|
| 149 | |
public boolean isClientValidationEnabled() |
| 150 | |
{ |
| 151 | 944 | return clientValidationEnabled; |
| 152 | |
} |
| 153 | |
|
| 154 | |
public String getFormValidationId() |
| 155 | |
{ |
| 156 | 909 | return formValidationId; |
| 157 | |
} |
| 158 | |
} |