0

编辑:这发生在任何组件 AJAX 调用期间。

我正在使用 ICEFaces 3.2.0 社区和 Spring Security 3.2 构建一个 Web 应用程序,直到几天前,一切都进展顺利。我在页面中有一个 ACE AutoCompleteEntry 组件,它的值附加了一个支持 bean,如下例所示:

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

附上的backing bean如下:

@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;
    }
}

问题是,每次我尝试测试组件而不是显示状态列表时,它都会重定向到我的主页的绝对路径,这会导致 404。在开发人员工具中,我看到以下错误:

> 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

开发者工具日志显示:

> [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)

我花了很多时间来解决这个问题和其他问题,但我已经没有想法了。如果有人有某种帮助,我将非常感谢您的帮助。

4

1 回答 1

1

如果您使用的是 JSF 2,那么您可以添加自己的异常处理程序,这应该能够捕获 ajax 请求。

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

看这里的例子,

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/

于 2013-02-26T16:15:05.490 回答