📄 rundataformbean.java
字号:
/**
* Get the value of the bean's <em>comments</em> field.
*
* @return The current value of the <em>comments</em> field
*/
public String getComments() {
return mComments;
}
/**
* Set the value of the bean's <em>comments</em> field.
*
* @param value The value to be set onto the <em>comments</em> field
*/
public void setComments(String value) {
mComments = value;
}
/**
* Retrieve the form bean's values.
*
* @return A transfer object representing the for bean's state
*/
public DTO getValues() {
DTO valueObject = super.getValues();
if (LOG.isDebugEnabled()) {
LOG.debug("getValues: Contents of the value object "
+ " (before) " + valueObject);
}
valueObject.setCanonicalId(RunData.CANONICAL_ID);
valueObject.setValue(RunData.FIELD_DATE, getDate());
valueObject.setValue(RunData.FIELD_DISTANCE, getDistance());
valueObject.setValue(RunData.FIELD_UNITS, getUnits());
valueObject.setValue(RunData.FIELD_TIME, getTime());
valueObject.setValue(RunData.FIELD_PACE, getPace());
valueObject.setValue(RunData.FIELD_ROUTE, getRoute());
valueObject.setValue(RunData.FIELD_RUN_TYPE, getRunType());
valueObject.setValue(RunData.FIELD_SHOES, getShoes());
valueObject.setValue(RunData.FIELD_COMMENTS, getComments());
if (LOG.isDebugEnabled()) {
LOG.debug("getValues: Contents of the value object "
+ " (after) " + valueObject);
}
return valueObject;
}
/**
* Update the form bean's values.
*
* @param valueObject Value object containing the new values
* to be applied to the form bean
*/
public void setValues(DTO valueObject) {
if (LOG.isDebugEnabled()) {
LOG.debug("setValues: Contents of the value object "
+ valueObject);
}
super.setValues(valueObject);
setDate(valueObject.getValue(RunData.FIELD_DATE));
setDistance(valueObject.getValue(RunData.FIELD_DISTANCE));
setUnits(valueObject.getValue(RunData.FIELD_UNITS));
setTime(valueObject.getValue(RunData.FIELD_TIME));
setPace(valueObject.getValue(RunData.FIELD_PACE));
setRoute(valueObject.getValue(RunData.FIELD_ROUTE));
setRunType(valueObject.getValue(RunData.FIELD_RUN_TYPE));
setShoes(valueObject.getValue(RunData.FIELD_SHOES));
setComments(valueObject.getValue(RunData.FIELD_COMMENTS));
}
/**
* Reset the state of the form bean.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
* @param container The current user's container object
*/
protected void reset(ActionMapping mapping, HttpServletRequest request,
UserContainer container) {
super.reset(mapping, request, container);
String day = request.getParameter(ConstantValues.STRING_DAY);
String month = request.getParameter(ConstantValues.STRING_MONTH);
String year = request.getParameter(ConstantValues.STRING_YEAR);
if (LOG.isDebugEnabled()) {
LOG.debug("reset: Day is " + day);
LOG.debug("reset: Month is " + month);
LOG.debug("reset: Year is " + year);
}
if (validRouteValues == null && validRunTypeValues == null
&& validShoeValues == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("reset: Resetting and defaulting options");
}
try {
loadDropDownOptions(container);
} catch (ServiceException ex) {
LOG.error("Unable to load drop down options", ex);
throw new FatalRuntimeException(ex);
}
}
if (!Utilities.isBlank(day) && !Utilities.isBlank(month)
&& !Utilities.isBlank(year)) {
Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
cal.set(Calendar.MONTH, Integer.parseInt(month));
cal.set(Calendar.YEAR, Integer.parseInt(year));
String value = Conversions.dateToString(cal.getTime());
if (LOG.isDebugEnabled()) {
LOG.debug("reset: Resetting date to '" + value + "'");
}
setDate(value);
setRoute(getDefaultObject(validRouteValues));
setRunType(getDefaultObject(validRunTypeValues));
setShoes(getDefaultObject(validShoeValues));
}
}
/**
* Retrieve any transfer objects that will be used to represent drop-down
* options from the backend. This will retrieve the appropriate records,
* convert them to <code>DropDownOptionFormBean</code>s, and store them
* on this form bean.
*
* @param container The user's container; used to find records
* @throws ServiceException If there is an error loading the options
*/
private void loadDropDownOptions(UserContainer container)
throws ServiceException {
Collection dtos = null;
IQueryService qService = container.getQueryService();
String runnerId = container.getUserName();
dtos = qService.findRoutesForRunner(runnerId);
validRouteValues = getDropDownOptions(dtos);
dtos = qService.findRunTypesForRunner(runnerId);
validRunTypeValues = getDropDownOptions(dtos);
dtos = qService.findShoesForRunner(runnerId);
dtos = getNonRetiredShoes(dtos);
validShoeValues = getDropDownOptions(dtos);
}
/**
* Convert a collection of transfer objects into a collection of
* <code>DropDownOptionFormBean</code>s.
*
* @param dtos The collection of transfer objects
* @return A collection of drop down option form beans
*/
private Collection getDropDownOptions(Collection dtos) {
Collection beans = new ArrayList();
DropDownOptionFormBean option = null;
DTO dto = null;
Boolean bool = null;
String value = null;
for (Iterator i = dtos.iterator(); i.hasNext();) {
dto = (DTO) i.next();
option = new DropDownOptionFormBean();
value = dto.getValue(ReferenceData.FIELD_DESCRIPTION);
option.setDisplayValue(value);
value = dto.getValue(HasGeneratedId.FIELD_ID);
option.setValue(value);
option.setDefault(isDefault(dto));
if (LOG.isDebugEnabled()) {
LOG.debug("getDropDownOptions: Adding the following option "
+ option);
}
beans.add(option);
}
return beans;
}
/**
* From a collection of <code>DropDownOptionFormBean</code>s, get the
* value of the one that is marked as default (if one is present). If more
* than one item in the collection is marked as default, the value from the
* first default item that is encountered will be returned.
*
* @param options A collection of drop down option form beans
* @return The value of the default option, or null if no default option is
* found.
*/
private String getDefaultObject(Collection options) {
DropDownOptionFormBean option = null;
for (Iterator i = options.iterator(); i.hasNext();) {
option = (DropDownOptionFormBean) i.next();
if (LOG.isDebugEnabled()) {
LOG.debug("getDefaultObject: Object " + option + " is default? "
+ option.isDefault());
}
if (option.isDefault()) {
return option.getValue();
}
}
return null;
}
/**
* From a collection of <code>DTO</code>s (representing Shoe objects),
* get only those that are not retired.
*
* @param dtos A collection of Shoe <code>DTO</code>s
* @return Those <code>DTO</code>s that are not retired
*/
private Collection getNonRetiredShoes(Collection dtos) {
ArrayList shoes = new ArrayList();
DTO temp = null;
for (Iterator i = dtos.iterator(); i.hasNext();) {
temp = (DTO) i.next();
if (!isRetired(temp)) {
shoes.add(temp);
}
}
return shoes;
}
/**
* Determine whether a <code>DTO</code> has a 'default' value of true. This
* method will inspect the <code>ReferenceData.FIELD_DEFAULT</code> value
* for the transfer object and will return true if it can be converted to
* a boolean representing some sort of true value, or false if it cannot.
*
* @param values The <code>DTO</code> to be checked
* @return True if the <code>DTO</code> is default, false otherwise
*/
private boolean isDefault(DTO values) {
String value = values.getValue(ReferenceData.FIELD_DEFAULT);
boolean bool = false;
try {
bool = Conversions.stringToBoolean(value).booleanValue();
} catch (Exception ex) {
bool = false;
}
return bool;
}
/**
* Determine whether a <code>DTO</code> has a 'retired' value of true. This
* method will inspect the <code>Shoe.FIELD_RETIRED</code> value
* for the transfer object and will return true if it can be converted to
* a boolean representing some sort of true value, or false if it cannot.
*
* @param values The <code>DTO</code> to be checked
* @return True if the <code>DTO</code> is retired, false otherwise
*/
private boolean isRetired(DTO values) {
String value = values.getValue(Shoe.FIELD_RETIRED);
boolean bool = false;
try {
bool = Conversions.stringToBoolean(value).booleanValue();
} catch (Exception ex) {
bool = false;
}
return bool;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -