String idScript = null;
if (_formSubmit)
_form = getNearestForm();
ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request);
// check the parameters that the user provided
if (_href != null) have++;
if (_action != null) have++;
if (_clientAction != null) have++;
if (_linkName != null) have++;
String tagId = getTagId();
// if only the _linkName or _tagId is set then we are creating the name attribute only.
if (have == 0 && !_formSubmit && tagId != null) {
return createNameAnchor(request, trb);
}
// if the anchor is submitting a consider this a submit level problem
// set the action to the form action.
if (_formSubmit) {
formAction = getFormAction();
if ((formAction != null) && (have == 0)) {
have++;
}
if (_action == null) {
_action = formAction;
_location = getFormLocation();
}
}
// if we have not specified a destination or we've specified too many
// then we need to report an error.
if (have == 0 || have > 1) {
String s = Bundle.getString("Tags_Anchor_InvalidAnchorURI",
new Object[]{getTagName(), requiredAttrs});
registerTagError(s, null);
return false;
}
if (_linkName != null) {
return createPageAnchor(request, trb);
}
if (_action != null) {
// report that action is not an action
if (!PageFlowTagUtils.isAction(request, _action)) {
String s = null;
if (_action.equals("")) {
s = Bundle.getString("Tags_NullBadAction", null);
}
else {
s = Bundle.getString("Tags_BadAction", _action);
}
registerTagError(s, null);
}
else {
//
// If the action we're submitting to is checking for double-submits, save a token in the session.
// This will be written out as a param (below), and will be checked in PageFlowRequestProcessor.
//
String token = PageFlowTagUtils.getToken(request, _action);
if (token != null) {
addParamInternal(Constants.TOKEN_KEY, token);
}
}
}
// we assume that tagId will over have override id if both
// are defined.
if (tagId != null) {
_state.id = tagId;
idScript = renderNameAndId(request, _state, null);
}
// Special case for name anchors
if (_clientAction != null) {
_state.href = "";
}
else {
// Add the scope-ID parameter, if the targetScope attribute is present.
if (_targetScope != null) {
addParamInternal(ScopedServletUtils.SCOPE_ID_PARAM, _targetScope);
}
if (_popupSupport != null) {
_popupSupport.addParams(this, request);
}
// Generate the opening anchor element
String uri = null;
try {
if (_action != null) {
uri = PageFlowTagUtils.rewriteActionURL(pageContext, _action, _params, _location);
}
else if (_href != null) {
uri = PageFlowTagUtils.rewriteHrefURL(pageContext, _href, _params, _location);
}
}
catch (URISyntaxException e) {
// report the error...
logger.error(Bundle.getString("Tags_URISyntaxException"));
String s = Bundle.getString("Tags_Anchor_URLException",
new Object[]{e.getMessage()});
registerTagError(s, e);
}
if (uri == null) {
if (hasErrors())
return false;
}
else {
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
_state.href = response.encodeURL(uri);
}
}
// We need to combine the onclick features
IScriptReporter sr = getScriptReporter();
if (_clientAction != null && srs.isFeatureWritten(CoreScriptFeature.DYNAMIC_INIT)) {
//@todo: we need to support onclick chaining here also...
String action = HtmlUtils.escapeEscapes(_clientAction);
String entry = ScriptRequestState.getString("netuiAction",
new Object[]{action});
_state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, entry);
// Jira 299
//_state.onClick = entry;
}
// if the user overrides the onclick we will ignore this
String onclick = _state.getAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK);
if (onclick == null) {
if (_formSubmit && formAction != null) {
String realFormName = getFormId();
String key = (_disableSecondClick ? "anchorDisableAndSubmitFormAction" : "anchorFormSubmitAction");
String entry = ScriptRequestState.getString(key, new Object[]{realFormName, _state.href});
_state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, entry);
// Jira 299
//_state.onClick = ScriptRequestState.getString("anchorFormSubmitAction",
// new Object[]{realFormName, _state.href});
if (_form != null)
_form.insureRealId();
}
else if (_disableSecondClick) {
String entry = ScriptRequestState.getString("anchorDisableAction", null);
_state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, entry);
}
else if (_popupSupport != null) {
_state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, _popupSupport.getOnClick(request,_state.href));
// Jira 299
//_state.onClick = _popupSupport.getOnClick(_state.href);
}
}
if (hasErrors())
return false;
trb.doStartTag(writer, _state);
// Emit javascript if this anchor needs to sumbit the form or open a popup window
if (_formSubmit && formAction != null || idScript != null || _popupSupport != null) {
InternalStringBuilder script = new InternalStringBuilder(32);
StringBuilderRenderAppender scriptWriter = new StringBuilderRenderAppender(script);
if (_formSubmit && formAction != null)
srs.writeFeature(sr, scriptWriter, CoreScriptFeature.ANCHOR_SUBMIT, true, false,
null);
if (_popupSupport != null)
_popupSupport.writeScript(request, srs, getScriptReporter(), scriptWriter);
if (idScript != null)
scriptWriter.append(idScript);