JQuery的AJAX的JSF / JSF标签都没有确定。找不到的FacesContext找不到、标签、AJAX、JQuery

2023-09-10 14:43:41 作者:浅眠

我在使用jQuery的Ajax和JSF组合面临的一个问题。我不是pretty的知道这是一个平常的问题,并且可以处理,但希望能得到解决。

下面是该方案。我们正在开发一个门户项目使用JSF。所以在页面上,我们需要加载行方面巨大的表中的数据(APPX 300-400有时)和每一行都会有一个链接,需要打开一个弹出窗口。所以为了不要打了页面的表现,我计划延迟加载的JSP(弹出内容)。所以想到了去了阿贾克斯。该JSP是一种具有不认识的AJAX负载的JSF标签。我明白当JSP负载阿贾克斯这将是一个普通的/独立(非jsf'tified)版本。

所以我的问题是:我怎么能在这情况下jsf'tified使JSF标签可以是可见的JSP(弹出内容)

目前我得到找不到FacesContext中。

我用下面的code:

  jQuery.ajax({
    键入:GET,
    缓存:假的,
    的contentType:text / html的;字符集= ISP-8859-1,
    网址:'<%= renderResponse.en $ C $卷曲(renderRequest.getContextPath()+/tempfolder/tempLoader.jsp)%>',
    数据:{参数1:66,参数2:88},
    成功:函数(MSG){
        jQuery的(loadContent。)的HTML(MSG)。
        jQuery的(#viewpopupdiv)儿童()显示()。
    }
});
 
jQuery Ajax

和我的jsp:

 <%@标签库的uri =htt​​p://java.sun.com/jsf/corepreFIX =F%>
<%@标签库的uri =htt​​p://java.sun.com/portletpreFIX =portlet的%>
<%@标签库的uri =htt​​p://www.ibm.com/jsf/html_extendedpreFIX =HX%>
<%@标签库的uri =htt​​p://java.sun.com/jsf/htmlpreFIX =H%>


< D​​IV ID =视图的风格=文本对齐:左>

<表类=viewpopupdiv的风格=宽度:480px;背景色:#efedea;边框宽度:薄;边框颜色:#FF6633;边境风格:固体;的cellpadding =0CELLSPACING =0的边界=0>
        &其中; TR>
            < TD>
                <表格样式=宽度:100%>
                    &其中; TR>
                        < TD>

                            <表格样式=宽度:100%;背景颜色:#424341;>
                                &其中; TR>
                                    < TD类=editLineHeaderDarkLeft>
                                        &LT;跨度类=&GT;线路ID&LT; / SPAN&GT; :功放; NBSP;&LT;跨度class="headerValueForPopup"><%=lineDetails.getDisplayableOrderLineId()%></span></td>
                                    &LT; TD类=editLineHeaderDarkCenter&GT;
                                        &LT;跨度类=&GT;订单号&LT; / SPAN&GT; :功放; NBSP;&LT;跨度class="orderNumberHeaderValueForPopup"><%=lineDetails.getDisplayableOrderHeaderId()%></span></td>
                                    &LT; TD类=editLineHeaderDarkRight&GT;&LT; D​​IV HREF =#的onclick =closePopupForEditLine('closepopupdiv')&GT;&LT; IMG类=关闭SRC ='&LT;%= imgUrl的%&GT;边境=0&GT;&LT; / DIV&GT;
                                    &LT; / TD&GT;
                                &LT; / TR&GT;
                            &LT; /表&gt;

&LT; TD类=editLineHeaderDarkLeft&GT;
&LT; D​​IV CLASS =chargeTypeDropListJQ&GT;
                                        &LT; H:selectOneMenu用于值=#{popupBean.chargeTypeId}的styleClass =selectOneMenu用于&GT;
                                            &LT; F:selectItems的值=#{popupBean.chargeType}/&GT;
                                        &LT; / H:selectOneMenu用于&GT;
                                    &LT; / DIV&GT;
&LT; / TD&GT;
                    &LT; / TR&GT;
                &LT; /表&gt;
&LT; / TD&GT;&LT; / TR&GT;&LT; /表&gt;&LT; / DIV&GT;
 

解决方案   

找不到的FacesContext

当您运行使用JSF组件为纯香草JSP JSP页面,而不必调用 FacesServlet的你会得到这个异​​常。这是一个负责创建 FacesContext中。请求的URL需要匹配&LT; URL模式&GT; FacesServlet的,因为它是被definied在的web.xml 把所有的JSF标签才能正常运行。

假设URL模式是 *。JSF ,那么你需要更改

 网​​址:'&LT;%= renderResponse.en $ C $卷曲(renderRequest.getContextPath()+/tempfolder/tempLoader.jsp)%&GT;',
 

 网​​址:'&LT;%= renderResponse.en $ C $卷曲(renderRequest.getContextPath()+/tempfolder/tempLoader.jsf)%&GT;',
 

I am facing a problem while using jquery ajax and jsf combination. I am not pretty sure if this is a usual problem and can be handled, but hoping to get a solution.

here is the scenario. we are developing a portal project with jsf. so on a page we have to load huge data in terms of rows in a table(appx 300-400 sometimes) and each row will have a Link which needs to open a popup. so in order not to hit the performance of the page, i am planning to lazy load the jsp(popup content). so thought to go for ajax. the jsp is having the jsf tags which are not recognizing by the ajax load. I understand when the jsp loads by ajax it will be a plain/independent (un jsf'tified) version.

so my question is : how can i make the jsp(popup content) in this scenario jsf'tified so that jsf tags can be visible.

currently i am getting cannot find FacesContext.

i am using the following code:

jQuery.ajax({
    type: "GET",
    cache: false,
    contentType: "text/html; charset=ISP-8859-1" ,
    url: '<%=renderResponse.encodeURL(renderRequest.getContextPath()+ "/tempfolder/tempLoader.jsp") %>',
    data:{param1:66, param2:88},
    success:function(msg) {    
        jQuery(".loadContent").html(msg);
        jQuery("#viewpopupdiv").children().show();
    }
});

And my jsp:

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>


<div id="view"  style="text-align:left">

<table class="viewpopupdiv" style="width:480px;background-color:#efedea;border-width: thin; border-color: #ff6633; border-style:solid;" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td>
                <table style="width:100%">
                    <tr>
                        <td>

                            <table style="width:100%;background-color:#424341;">
                                <tr>
                                    <td class="editLineHeaderDarkLeft">  
                                        <span class="">Line ID</span> :&nbsp;<span class="headerValueForPopup"><%=lineDetails.getDisplayableOrderLineId()%></span></td>
                                    <td class="editLineHeaderDarkCenter">  
                                        <span class="">Order Number</span>  :&nbsp;<span class="orderNumberHeaderValueForPopup"><%=lineDetails.getDisplayableOrderHeaderId()%></span></td> 
                                    <td class="editLineHeaderDarkRight"><div href="#" onclick="closePopupForEditLine('closepopupdiv')"><img class="close" src='<%=imgURL%>' border="0"></div>
                                    </td>
                                </tr>
                            </table>

<td class="editLineHeaderDarkLeft">                              
<div class="chargeTypeDropListJQ">  
                                        <h:selectOneMenu  value="#{popupBean.chargeTypeId}" styleClass="selectOneMenu">
                                            <f:selectItems value="#{popupBean.chargeType}" />
                                        </h:selectOneMenu>
                                    </div>
</td>
                    </tr>  
                </table>
</td></tr></table></div>

解决方案

cannot find FacesContext

You will get this exception when you run a JSP page with JSF components as "plain vanilla" JSP without invoking the FacesServlet. It's the one responsible for creating the FacesContext. The request URL needs to match the <url-pattern> of the FacesServlet as it is been definied in web.xml to get all the JSF tags to run properly.

Assuming that the URL pattern is *.jsf, then you need to change the

url: '<%=renderResponse.encodeURL(renderRequest.getContextPath()+ "/tempfolder/tempLoader.jsp") %>',

to

url: '<%=renderResponse.encodeURL(renderRequest.getContextPath()+ "/tempfolder/tempLoader.jsf") %>',