如何在JSP中使用视图参数? [英] How to use view-params with JSP?

查看:102
本文介绍了如何在JSP中使用视图参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用视图参数在JSF 2中获取可添加书签的URL,但是我使用JSP,而我可以找到的所有帮助和示例都使用facelets.到目前为止,这是我想要做的:

I would like to use view parameters to get bookmarkable URLs with JSF 2, but I use JSPs and all the help and examples I can find, uses facelets. Here is want I have done so far:

search.jsp(调用页面):

search.jsp (calling page):

  <t:commandLink action="...">
      <f:param name="param1" value="foo"/>
      <h:outputText value="..."/>                  
  </t:commandLink>

faces-config.xml:

faces-config.xml:

  <navigation-rule>
    <navigation-case>
      <from-outcome>go_edit</from-outcome>
      <to-view-id>/views/edit.jsp</to-view-id>
      <redirect>
        <view-param>
          <name>param1</name>
          <value>#{edit.param1}</value>
        </view-param>
      </redirect>
    </navigation-case>
  </navigation-rule>

Edit.java(编辑页面支持bean):

Edit.java (edit page backing bean):

public class Edit extends ... {

  private String param1;

  public String getParam1(){
    return param1;
  }

  public void setParam1(String param1){
    this.param1 = param1;
  }

  ...
}

我认为问题在于,我没有将视图参数添加到编辑页面(例如edit.jsp).我只发现了facelet示例,如下所示:

I think the problem is, that I didn't add the view params to the edit page (e.g. edit.jsp). I only found facelet examples, which look like this:

<f:metadata>
    <f:viewParam name="id" value="#{bean.id}" />
</f:metadata>

我的问题是,我可以使用JSP视图参数吗?有人可以提供或指出我一个完整的例子吗?尤其是带有目标页面的部分(例如edit.jsp).

My question is, can I use JSP view params? Can someone provide or point me to an complete example? Especially the part with the target page (e.g. edit.jsp).

推荐答案

这是不可能的.自2009年12月JSF 2.0以来,已不推荐使用(将近4年前!).所有新的JSF 2.x特定标记都可用于 Facelets ,而不是 JSP .基本上,使用JSP时,只有特定于JSF 1.x的标签可用.换句话说,JSF 不能使用JSF 2.x标记<f:metadata><f:viewParam><f:ajax><h:head><h:outputScript>等.

This isn't possible. JSP is deprecated since JSF 2.0 in December 2009 (almost 4 years ago already!). All new JSF 2.x specific tags are available to Facelets only and not to JSP. Basically, with JSP you've only JSF 1.x specific tags available. In other words, the JSF 2.x tags <f:metadata>, <f:viewParam>, <f:ajax>, <h:head>, <h:outputScript>, etc are not available to JSP.

使用过时的技术毫无意义.现在是迁移的时候了.

There's no point working with deprecated technology. It's high time to migrate.

这篇关于如何在JSP中使用视图参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆