简体   繁体   English

<h:commandLink> 不能与嵌套一起使用 <f:view> 标记但是 <h:outputLink> 正在工作

[英]<h:commandLink> not working with nested <f:view> tag but <h:outputLink> is working

I am working on a web-application in jsf. 我正在使用jsf开发Web应用程序。 My question is regarding the working of <h:commandLink> . 我的问题是有关<h:commandLink>

I tried using <h:commandLink> for doing the stuff which I can do with <h:outputLink> , just for testing.(I know it is a bad idea to use <h:commandLink> for static navigation). 我尝试使用<h:commandLink>进行我可以使用<h:outputLink> ,仅用于测试。(我知道使用<h:commandLink>进行静态导航是一个坏主意)。

My <h:commandLink> is present in a file called CustomerRight.jsp . 我的<h:commandLink>存在于名为CustomerRight.jsp的文件中。

So in my file CustomerRight.jsp , I have the code as shown below: 因此,在我的文件CustomerRight.jsp中 ,我具有如下所示的代码:

<f:view>
<h:commandLink action="/pages/accountSettings/ToggleMessageService.jsp" value="Click here"></h:commandLink>
</f:view>

Now this file is included in another jsp called Home.jsp as shown below: 现在,此文件包含在另一个名为Home.jsp的 jsp中,如下所示:

<f:view>
   <h:form>
      <jsp:include page="CustomerRight.jsp"></jsp:include>
   </h:form>
</f:view>

Now as we can see when the page is included in Home.jsp , it will act as a nested <f:view> tag. 现在我们可以看到该页面何时包含在Home.jsp中 ,它将作为嵌套的<f:view>标记。 Because of this, the <h:commandLink> is not working. 因此, <h:commandLink>无法正常工作。 It is re-deirecting me to the same page, whereas if I use a <h:outputLink> instead of it, that is working fine. 它将我重新引导到同一页面,但是如果我使用<h:outputLink>代替它,则工作正常。

Can anyone explain me why the <h:commandLink> is not working but the <h:outputLink> is working in case of nested <f:view> tag? 谁能解释为什么<h:commandLink>不起作用,但<h:outputLink>在嵌套的<f:view>标记下起作用的原因?

If I remove the <f:view> tag from the CustomerRight.jsp , the commandLink works fine (since there is no nested <f:view> tag now) 如果我从CustomerRight.jsp中删除<f:view>标记,则commandLink可以正常工作(因为现在没有嵌套的<f:view>标记)

Also what is the significance of <f:view> tag? 还有<f:view>标签的意义是什么? If I don't use it at all in any of the jsps, the page is not rendered. 如果我在任何jsps中都不使用它,则不会呈现该页面。 I get an exception saying "java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@1226eca not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?" 我收到一个异常消息,提示"java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@1226eca not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?"

First of all, you're using legacy JSP view technology which was deprecated and succeeded by Facelets (XHTML) since JSF 2.0 in 2009. If you're just starting with JSF, make sure that you don't look at age-old learning resources. 首先,您使用的是自2009年JSF 2.0以来,Facelets(XHTML)弃用并成功使用的旧版JSP视图技术。如果您只是从JSF开始,请确保您不要研究过时的学习方法资源。 Namely, the <f:view> behaves differently in Facelets, so if you're researching for answers, any answer targeted at Facelets doesn't apply to JSP and may end up to confuse you. 即, <f:view>在Facelets中的行为有所不同,因此,如果您正在研究答案,那么针对Facelets的任何答案都不适用于JSP,并且可能最终使您感到困惑。

As to the concrete problem, in JSP there can be only one <f:view> and it must be the top level JSF component. 对于具体问题,在JSP中只能有一个 <f:view> ,它必须是顶级JSF组件。 It represents the UIViewRoot instance. 它代表UIViewRoot实例。 You can't nest multiple <f:view> in JSP. 您不能在JSP中嵌套多个<f:view> In JSP's successor Facelets it is optional, and doesn't need to be top level one, and there can be multiple, basically extending each other. 在JSP的继任者Facelets中,它是可选的,并且不必是顶级的,并且可以有多个,并且基本上彼此扩展。

You shouldn't have a <f:view> in the include file. 包含文件中不应包含<f:view> You can at most have a <f:subview> in the include file if you intend to reuse the same include file multiple times, otherwise duplicate component ID errors will occur for the included content. 如果您打算多次重用同一个包含文件,则包含文件中最多可以有一个<f:subview> ,否则包含的内容将发生重复的组件ID错误。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM