我有一个Facelets页面和一个h:commandLink
。
<h:commandLink value="#{View} »"
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();
}
下面是我的myReceiptPage.xhtml
页面代码,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div 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">
<head>
</head>
<f:view>
<body>
<h:form>
<ui:insert>
<ui:include src="/someOtherPage.xhtml" />
</ui:insert>
<h:outputText value="#{facesContext.externalContext.requestParameterMap.UserID}" />
</h:form>
<body>
</f:view>
<div>
当我单击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
}
}
以下是例外情况(显示在窗口上),
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)
造成这种情况的可能原因是什么?
编辑:view.xhtml
的内容粘贴在下面。
<!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>
添加到异常列表:<rich:tabPanel selectedTab="#{someBean.getSelectedTab}">
上面的getSelectedTab
方法看起来像这样,
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();
}
}
我必须说,我仍然没有在任何xhtml文件中看到表达式#{myBean.userID}
,但问题可能是因为您的getter方法getUserId()
被声明为void
,所以这里的属性userId
被认为是不可读的。您必须从getter返回属性。