JSF在托管bean中读取动态输入元素

时间:2011-11-08 12:02:41

标签: html forms jsf

我有一个非常复杂的JSF页面(我们使用带有facelet的JSF2),其中我必须“插入”一个纯html表单部分(它代表一个WYSIWYG模板,用于稍后将创建为Pdf的文档)。 非常简化的页面看起来像

<h:form id="formEditDoc">
   <p:commandButton styleClass="commandButton" value="Save"
      actionListener="#{myBean.myAction}" update="masterForm:msg">
   </p:commandButton>

   <!-- some jsf controls here -->
   ....

   <!-- this is my dynamic section -->
   <input id="ft2" type="text" value="foo"/>
</h:form>

在托管bean中myBean(请求作用域)我有动作监听器,我尝试以这种方式获取“foo”字符串:

String text1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("ft2");

但我无法获得价值。 Text1始终为null。我甚至尝试将ajax = false设置为commandButton,但没有任何改变。 关于我做错了什么的任何想法?

1 个答案:

答案 0 :(得分:4)

输入的name=value对作为请求参数name=value发送,而不是id=value。您需要设置name属性。

<input id="ft2" name="ft2" type="text" value="foo"/>

对具体问题

无关,我建议改用@ManagedProperty来设置值:

@ManagedProperty("#{param.ft2}")
private String ft2;