【问题标题】:Prettyfaces link with user input as parameterPrettyfaces 链接用户输入作为参数
【发布时间】:2017-08-13 17:03:27
【问题描述】:

我的 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>

我还得到了一个带有init 方法的bean,该方法用@URLAction(onPostback = false) 注释。

我想在这个方法中读取传递的参数。参数不在 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 的代码和映射。
  • 感谢您的提示!信息够了吗?

标签: jsf prettyfaces


【解决方案1】:

您必须将参数绑定到您的模式中的 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

【讨论】:

  • 您将如何处理用户输入?基本上,我希望用户填写月份和年份,然后通过单击 pretty:link 将用户重定向到 addEntity 页面。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-12
  • 1970-01-01
  • 2011-10-04
  • 1970-01-01
  • 2017-09-03
  • 1970-01-01
  • 2014-05-19
相关资源
最近更新 更多