0

I have three drop downs one populates the other based onchange event, making ajax call on each. Following are the html, javascript and struts 2 action class for one of them. When I looked at the dev tools in IE, I am getting 404 error.

enter image description here

JSP code:

<tr id="ticketTypeOptions" style="visibility:hidden">
                    <td>
                    
                        <select id="ticketTypeList" onchange="updateActions()" property="selTicketType">
                            <s:set value="ticketTypeOptions" var="ticketTypes" />
                            <option value="-1"><s:property value="getText('brules.ticketTypeDefault')" /></option>
                            <s:iterator value="ticketTypes" var="ticket">
                                <c:if test="${USERINFO.admin || (USERINFO.planogramAdmin && ticket.ticketTypeId == pogType)}">
                                    <option value="${ticket.ticketTypeId}">${ticket.name}</option>
                                </c:if>
                            </s:iterator>
                        </select>
                    </td>
                </tr>
                <tr id="actionTypeLabel" style="visibility:hidden">
                    <td>
                        <s:property value="getText('brules.mstActnTypId')"/>:
                    </td>
                </tr>
                <tr id="actionTypeOptions" style="visibility:hidden">
                    <td>
                        <s:select property="selActionType" name="actionTypeList" onchange="updateReasons()" list="%{{}}"/>
                    </td>
                </tr>
                <tr id="reasonTypeLabel" style="visibility:hidden">
                    <td>
                        <s:property value="getText('brules.mstRsnTypId')"/>:
                    </td>
                </tr>
                <tr id="reasonTypeOptions" style="visibility:hidden">
                    <td>
                        <s:select property="selReasonType" name="reasonTypeList" list="%{{}}" onchange="updateCombinationButton()"/>
                    </td>
                </tr>

Javascript code:

function updateActions(){
    var ticketType = getListValue(element('ticketTypeList'));
    clearActions();
    if (ticketType >= 0) {
        var actionUrl = 'getActionTypes.action?&selectedTicketType=' + ticketType;
        sendAjaxRequest(actionUrl, createActions);  
        showArea('actionTypeLabel');
        showArea('actionTypeOptions');
        showArea('addCombinationButton');
    }
}
function getListValue(listComponent) {
    var index = listComponent.selectedIndex;
    return listComponent[index].value;
}
function createActions(){
    var obj = element('actionTypeList');
    eval(ajax.response); // Executing the response from Ajax as Javascript code
}
function showArea(id) {
    element(id).style.visibility = 'visible';
}
function element(id) {
    return document.getElementById(id);
}
function sendAjaxRequest(url, callBack){
    ajax.method="GET";
    ajax.queryStringSeparator="&";
    ajax.URLString="";  
    ajax.requestFile = url; // Specifying which file to get
    ajax.onCompletion = callBack;   // Specify function that will be executed after file has been found
    ajax.runAJAX();     // Execute AJAX function
}

Action Class

public class GetRuleTypesAction extends BaseAction implements ModelDriven<EditBusinessRuleForm> {
    
    private static transient Logger logger = Logger.getLogger(GetRuleTypesAction.class);
    private EditBusinessRuleForm currForm = new EditBusinessRuleForm();
    private String selectedTicketType;
    private String rndval;
    
    
    public String getRndval() {
        return rndval;
    }

    public void setRndval(String rndval) {
        this.rndval = rndval;
    }

    public EditBusinessRuleForm getCurrForm() {
        return currForm;
    }

    public void setCurrForm(EditBusinessRuleForm currForm) {
        this.currForm = currForm;
    }

    public String getSelectedTicketType() {
        return selectedTicketType;
    }

    public void setSelectedTicketType(String selectedTicketType) {
        this.selectedTicketType = selectedTicketType;
    }

    @Override
    public EditBusinessRuleForm getModel() {
        return currForm;
    }

    public String execute()  {

        logger.debug("GetRuleTypesAction:updateActions() action called");
        String forward = Constants.SUCCESS;
        try {
            String selectedTicketType = getRequest().getParameterValues("selectedTicketType")[0];
            List newActions = BusinessRuleManager.getActionTypes(selectedTicketType);
            currForm.setActionTypeOptions(newActions);
            getRequest().setAttribute("types", newActions);            
        } catch (Exception e) {
            logger.error(e);
            addActionError("Unexpected Error Occured.  The associated error message is: "+e.getMessage());
            forward = Constants.FAILURE;
        }       
        return forward;
   }
}

struts.xml snippet

<action class="com.homedepot.mm.mf.mst.actions.ajax.GetRuleTypesAction" name="getActionTypes" >
            <result name="success">/pages/ajaxFragments/ruleType.jsp"></result>
            <result name="showSelList">/pages/ajaxFragments/tktActnRsn.jsp"></result>
            <result name="failure">/pages/ajaxFragments/ajaxFailure.jsp"></result>
        </action>

ruleType.jsp

<%@ taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 

<c:if test="${empty types}">
    var selDesc = '<s:property value="getText('brules.typeDefault')"/>';
    obj.options[obj.options.length] = new Option(selDesc,'-1');
</c:if>

<c:forEach var="node" items="${types}" >    
    var nodeVal='<c:out value="${node.value}" />';
    var nodeName='<c:out value="${node.name}" />';  
    obj.options[obj.options.length] = new Option(unescapeValue(nodeVal),unescapeValue(nodeName));
</c:forEach>

Does anyone know why it is throwing 404?

Roman C
  • 49,761
  • 33
  • 66
  • 176
gcpdev-guy
  • 460
  • 1
  • 10
  • 23
  • There should me more description of error message, i.e. [this](https://stackoverflow.com/a/18420429/573032) is similar answer – Roman C Aug 18 '21 at 08:57
  • There are many reasons this could be happening, from a config/package issue (e.g., the action’s config ends up not being at the app root) to a BaseAction or interceptor issue that 404s for some reason. There’s nothing else immediately obvious. – Dave Newton Aug 18 '21 at 12:20

0 Answers0