Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf FacesContext仅第一次失去其上下文值_Jsf_Facelets_Jsf 1.2 - Fatal编程技术网

Jsf FacesContext仅第一次失去其上下文值

Jsf FacesContext仅第一次失去其上下文值,jsf,facelets,jsf-1.2,Jsf,Facelets,Jsf 1.2,我有一个带有一个h:commandLink的Facelets页面 <h:commandLink value="#{View} &#187;" onclick="return myJavaScript('#{myBean.param1}');"> </h:commandLink> function myJavaScript(paramReceived) { var relPath = "/myWarName/Pages/myReceiptPage.

我有一个带有一个
h:commandLink
的Facelets页面

<h:commandLink value="#{View} &#187;" 
    onclick="return myJavaScript('#{myBean.param1}');">
</h:commandLink>

function myJavaScript(paramReceived)
{
   var relPath = "/myWarName/Pages/myReceiptPage.jsf?"
                    + myActionValue;
    billWindow = window.open(relPath, '', 'width=' + width + ',height='
                    + height + ',top=' + top + ',left=' + left
                    + ',scrollbars=1,resizable=1');
    billWindow.focus();
}
当我单击
h:commandLink
时,会调用Java脚本并打开一个窗口,但下面的异常仅是第一次。从第二次开始,当我再次单击
h:commandLink
时,窗口将毫无例外地打开,数据已正确填充

当我点击
h:commandLink
PhaseListener被调用时,它正在调用一个方法。下面是代码

public void getUserId()
    {
        try
        {
            FacesContext context = FacesContext.getCurrentInstance(); 
            ExternalContext externalContext = context.getExternalContext();
                    //Code continues
        }
            Catch(Exception E)
            {
              //Am getting to know the exception here
             }
      }
以下是例外情况(显示在窗口上)

可能的原因是什么

编辑:将
视图的内容粘贴到下面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:t="http://myfaces.apache.org/tomahawk">
<head>
</head>
<h:form id="myFormId">
<ui:insert>
    <ui:include src="/myWarName/Pages/someOtherPage.xhtml" />  //Guess, problem is with this include. 
//This include is also there in myReceiptPage.xhtml page.
</ui:insert>

<rich:tabPanel selectedTab="#{myBean.getSelectedTab}">
    <rich:tab name="Tab Name">
        <h:panelGroup>
            <ui:insert>
               <ui:include src="somePage1.xhtml" />
            </ui:insert>
        </h:panelGroup>
        <h:panelGroup>
            <ui:insert>
                <ui:include src="somePage2.xhtml" />
            </ui:insert>
        </h:panelGroup>
</rich:tab>
</h:form
</html>

我必须说,我仍然没有在任何xhtml文件中看到表达式
{myBean.userID}
,但问题可能是因为getter方法
getUserId()
被声明为
void
,所以这里的属性
userID
被认为是不可读的。您必须从getter返回属性。

这是整个堆栈跟踪吗?看起来有一个潜在的原因导致EL阻塞。我们在这里看不到
view.xhtml
,而在这里放置是有问题的EL。@kolossus除了那个例外,我还得到了NullPointerException。这在我的问题中已经更新了。@partlov还包括了
view.xhtml
code。我曾在一个地方发表评论,我怀疑其中有一些problem@VikasV
FacesContext.getCurrentInstance()
通常在非托管bean中进行调用时返回null。
someBean
是否正确声明和定义范围?
javax.faces.FacesException: javax.el.ELException: /view.xhtml @192,150 userID="#{myBean.userID}": Error reading 'userID' on type com.myBean
        at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
        at org.richfaces.component.UITabPanel.getValue(UITabPanel.java:103)
        at org.richfaces.renderkit.TabPanelRendererBase.encodeTabs(TabPanelRendererBase.java:309)
        at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeBegin(TabPanelRenderer.java:228)
        at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeBegin(TabPanelRenderer.java:180)
        at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:100)
        at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:928)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
        at org.jboss.portletbridge.application.PortletViewHandler.renderView(PortletViewHandler.java:247)
        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:t="http://myfaces.apache.org/tomahawk">
<head>
</head>
<h:form id="myFormId">
<ui:insert>
    <ui:include src="/myWarName/Pages/someOtherPage.xhtml" />  //Guess, problem is with this include. 
//This include is also there in myReceiptPage.xhtml page.
</ui:insert>

<rich:tabPanel selectedTab="#{myBean.getSelectedTab}">
    <rich:tab name="Tab Name">
        <h:panelGroup>
            <ui:insert>
               <ui:include src="somePage1.xhtml" />
            </ui:insert>
        </h:panelGroup>
        <h:panelGroup>
            <ui:insert>
                <ui:include src="somePage2.xhtml" />
            </ui:insert>
        </h:panelGroup>
</rich:tab>
</h:form
</html>
public class myBean implements Serializable{
 public String getSelectedSubTab()
 {
   FacesContext con=FacesContext.getCurrentInstance();  
   ExternalContext externalContext = con.getExternalContext();
   String remoteUserId = externalContext.getRemoteUser();
   User user = UserServiceUtil.getUserById(Long.parseLong(remoteUserId));
   this.userID = user.getScreenName();          
 }
}