繁体   English   中英

Prettyfaces链接用户输入作为参数

[英]Prettyfaces link with user input as parameter

我在xhtml中得到以下代码:

<h:inputText binding="#{year}" />
<h:inputText binding="#{month}" />

<pretty:link value="Create" mappingId="pretty:addEntity">
    <f:param name="year" value="#{year.value}" />
    <f:param name="month" value="#{month.value}" />
    Create Entity
</pretty:link>

我也得到了一个带有@URLAction(onPostback = false)init方法的bean。

我想在此方法中读取传递的参数。 参数不在JSF的请求参数映射中,也不在查询字符串的一部分( com.ocpsoft.pretty.PrettyContext.getCurrentInstance().getRequestQueryString()

我如何将那些参数传递给init方法,而不将它们绑定到支持bean?

import com.ocpsoft.pretty.faces.annotation.URLAction;
import com.ocpsoft.pretty.faces.annotation.URLMapping;

import de.financeme.view.menu.NaviCase;

import javax.annotation.ManagedBean;
import javax.faces.bean.ViewScoped;

import lombok.Getter;
import lombok.Setter;

@ManagedBean
@ViewScoped
@URLMapping(id = "addEntity", pattern = "/entity/add", viewId = "/entity/add.xhtml")
public class Bean {

  @Getter
  @Setter
  private String month;

  @Getter
  @Setter
  private int year;

  @URLAction(onPostback = false)
  public void init() {
    // month = null
    // year = 0
  }
}

即使将它们绑定到支持bean。 我没有调用任何提交功能。 因此,它们不会存储在各自的字段中。

怎么了? 我在这里想念什么?

您必须将参数绑定到模式中的bean。 像这样:

<pretty:link value="Create" mappingId="pretty:addEntity">
    <f:param name="year" value="2017" />
    <f:param name="month" value="12" />
    Create Entity
</pretty:link>

和豆:

@ManagedBean
@ViewScoped
@URLMapping(id = "addEntity", 
    pattern = "/entity/#{bean.year}/#{bean.month}/add", 
    viewId = "/entity/add.xhtml")
public class Bean {

  // ...

}

现在,您将获得如下链接:

/entity/2017/12/add

暂无
暂无

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

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