When setting up the search fields via the approach used
in the example, after entering a seach value, the
search input field is cleared. This is kinda nice when
you are using navigation, so when you press 'first',
it'll take you back to the beginning of your
table/view. When using the search tag on the
otherhand, the search value is left in the input field
and so when 'first' is selected, you are left on the
same row. This behavior is also nice in some respects,
though the application I'm currently working relied on
the other behavior (input field clear). I believe the
best solution would be add a new attribute to the
DbSearchTag in order to allow for either behavior
(defaulting of course to the current behavior). The
changes to implement would be (attribute name
'usePriorValue'):
--------------------------------------
public class DbSearchTag extends
TagSupportWithScriptHandler
{
[...]
private String id = null;
private String usePriorValue = "true"; // MGS
/**
[...]
return defaultValue;
}
/**
* Method to set the value of the tag usePriorValue
parameter.
*
* @param String containing either "true" or
"false" indicating
* to use the prior entered search value or not.
*/
public void setUsePriorValue(String usePrior)
{
if ((usePrior == null) ||
("".equals(usePrior.trim())))
usePriorValue = "true"; // default to true
always
else
usePriorValue = usePrior.trim();
}
/**
* Method used to retrieve the current value of the
usePriorValue
* parameter.
*
* @return String containing "true" or "false"
indicating to use
* prior entered search value or not. Defaults to
"true" (use it).
*/
public String getUsePriorValue()
{
return usePriorValue;
}
/**
[...]
public int doEndTag() throws
javax.servlet.jsp.JspException
{
[...]
int fieldId = field.getId();
boolean usePrior =
"true".equalsIgnoreCase(usePriorValue); // MGS
/*
[...]
tagBuf.append("value=\"");
if ((usePrior) && (oldValue != null)) // MGS
{
tagBuf.append(oldValue);
}
else if (defaultValue != null)
{
tagBuf.append(defaultValue);
}
[...]
------------------
The new attribute needs to be added the the dbforms.tld
under the 'search' tag:
<attribute>
<name>usePriorValue</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
These changes allow the DbSearchTag to use the current
behavior (reload the last searched value into the input
field) and to ignore the last (prior) searched value.