Fred
Fred

Reputation: 29

ICEFaces AJAX redirect to 404

EDIT: This occurs during any component AJAX call.

I am building a web application using ICEFaces 3.2.0 community along with Spring Security 3.2 Everything has been going very well up until a few days ago. I have an ACE AutoCompleteEntry component in the page with a backing bean attached to the value as the following example:

<ace:autoCompleteEntry id="autoCompleteState"
                   label="State"
                   labelPosition="top"
                   value="#{autoCompleteEntry.selectedText}"
                   rows="10" width="160"
                   filterMatchMode="startsWith">
    <f:selectItems value="#{autoCompleteEntry.states}"/>
</ace:autoCompleteEntry>

The backing bean attached is as follows:

@ManagedBean(name=AutoCompleteEntry.BEAN_NAME)
@SessionScoped

public class AutoCompleteEntry implements Serializable {
    public static final String BEAN_NAME = "autoCompleteEntry";

    public static final String STATE_FILENAME = "State_Names.txt";
    public static final String RESOURCE_PATH = "/resources/selectinputtext/";

    public AutoCompleteEntry() {        
    }

    public List<SelectItem> states;    
    public List<SelectItem> getStates() {
        if(states == null) {
            states = new ArrayList<SelectItem>();
            for(String state : readStateFile()) {
                states.add(new SelectItem(state));
            }
        }
        return states;
    }

    private String selectedText = null;
    public String getSelectedText() {return selectedText;}
    public void setSelectedText(String selectedText) {this.selectedText = selectedText;}

    private static List<String> readStateFile() {
        InputStream fileIn = null;
        BufferedReader in = null;

        try {
            FacesContext fc = FacesContext.getCurrentInstance();
            ExternalContext ec = fc.getExternalContext();
            fileIn = ec.getResourceAsStream(AutoCompleteEntry.RESOURCE_PATH + STATE_FILENAME);

            if(fileIn != null) {
                in = new BufferedReader(new InputStreamReader(fileIn));
                List<String> loadedStates = new ArrayList<String>(53);
                String read;
                while((read = in.readLine()) != null) {
                    loadedStates.add(read);
                }

                return loadedStates;
            }
        }catch (IOException failedRead) {
            failedRead.printStackTrace();
        }finally {
            try {
                if(in != null) {
                    in.close();
                }
            }catch (IOException failedClose) {
                failedClose.printStackTrace();
            }
        }

        List<String> errorReturn = new ArrayList<String>(1);
        errorReturn.add("Error Loading State List");
        return errorReturn;
    }
}

The problem is that each time I attempt to test the component instead of bringing up a list of the States it redirects to an absolute path of my main page, which results in a 404. In developer tools I see an error of:

> Uncaught TypeError: Cannot read property 'value' of undefined
bridge.uncompressed.js.jsf:2701
namespace.onAfterUpdate.viewIDElement bridge.uncompressed.js.jsf:2701
apply bridge.uncompressed.js.jsf:122
(anonymous function) bridge.uncompressed.js.jsf:484
(anonymous function) bridge.uncompressed.js.jsf:363
(anonymous function) bridge.uncompressed.js.jsf:240
broadcast bridge.uncompressed.js.jsf:483
(anonymous function) bridge.uncompressed.js.jsf:1928
sendEvent jsf.js.jsf:1447
AjaxEngine.req.sendRequest jsf.js.jsf:1333
request jsf.js.jsf:1834
fullSubmit bridge.uncompressed.js.jsf:2309
submit bridge.uncompressed.js.jsf:2314
iceSubmit compat.uncompressed.js.jsf:1523
onclick

The developer tools log shows:

> [window] persisted focus for element "autoCompleteState_input"
bridge.uncompressed.js.jsf:1252
[window] full submit to localhost:8181/HHCA_Portal/pages/secure/HHCA.jsf
javax.faces.execute: @all
javax.faces.render: patientRecordsForm
javax.faces.source: autoCompleteState_input
view ID: v33tl98j
event type: unknown bridge.uncompressed.js.jsf:1252
XHR finished loading: "localhost:8181/HHCA_Portal/pages/secure/HHCA.jsf".
jsf.js.jsf:1334
AjaxEngine.req.sendRequest jsf.js.jsf:1334
request jsf.js.jsf:1834
fullSubmit bridge.uncompressed.js.jsf:2309
ice.ace.AjaxRequest ace-jquery.uncompressed.js.jsf:20854
ice.ace.ab ace-jquery.uncompressed.js.jsf:20779
ice.ace.Autocompleter.getUpdatedChoices autocompleteentry.js.jsf:695
ice.ace.Autocompleter.onObserverEvent autocompleteentry.js.jsf:637
(anonymous function)

I have spent many hours working on this and other issues, and I have run out of ideas. If someone has some kind of assistance I would really appreciate the help.

Upvotes: 0

Views: 560

Answers (1)

Avinash Singh
Avinash Singh

Reputation: 3787

If you are using JSF 2 then you can add your own exception handler , this should be able to capture ajax requests.

<factory>
  <exception-handler-factory>
    test.MyExceptionHandlerFactory
  </exception-handler-factory>
</factory>

see the examples here ,

http://balusc.blogspot.com/2012/03/full-ajax-exception-handler.html

http://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/

Upvotes: 1

Related Questions