如何获取p:inputText值并将其设置为f:param值?

时间:2012-08-21 15:36:22

标签: jsf primefaces spring-webflow

我有一个xhtml页面如下

    <p:inputText id="inputFilterKey" name="inputFilterKey" value="#{key}"  />
    <p:commandButton id="filterByKey" action="searchByKey" value="Search" ajax="false">
             <f:param name="filterKey" value=? />
    </p:commandButton>

参数'filterKey'应该具有user在inputText中提供的值。值'#{key}'是在spring webflow中定义的流量范围变量。也就是说,它不是从后面的bean中获取的。我应该如何获得inputText的值?以下是需要时的流程定义。

    <transition on="searchByKey" to="editTexts" >
        <set name="flowScope.key" value="requestParameters.filterKey"/>
        <evaluate expression="textManager.searchByKey(key)" result="viewScope.textsByKey" result-type="dataModel"/>
    </transition>

由于

1 个答案:

答案 0 :(得分:0)

这是不可能的。在呈现/显示表单时评估<f:param value>,而不是在提交/处理表单时评估。{/ p>

我不熟悉Spring Webflow,但这是IMO一个非常奇怪的设计。如果您正在以正确的方式做事,您可能想与SWF人确认。也许您应该在构造/初始化期间将SWF变量作为托管bean属性注入?

无论如何,有一些方法可以获取提交的值,而无需将输入组件的值绑定到托管bean属性。其中一个是通过@ManagedProperty

直接从请求参数映射中获取
@ManagedProperty("#{param['formId:inputFilterKey']}")
private String key; // +setter

或当托管bean的范围比请求范围更广时:

String key = externalContext.getRequestParameterMap().get("formId:inputFilterKey");

formId:inputFilterKey只是name组件生成的HTML <input>元素表示的<p:inputText>