Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用多个表单实例JSF2.0_Jsf_Jsf 2_Facelets_Primefaces - Fatal编程技术网

使用多个表单实例JSF2.0

使用多个表单实例JSF2.0,jsf,jsf-2,facelets,primefaces,Jsf,Jsf 2,Facelets,Primefaces,我的jsf应用程序是这样设计的,通过单击菜单项,相应的页面将显示在新创建的选项卡中。选项卡上显示的页面有自己的表单元素&backingbean。 通常情况下,这很有效,但无法找到一种方法来解决同时使用同一表单的多个实例的情况,例如,同时打开更多的“添加新员工”选项卡。 我尝试将@SessionScoped托管bean与包含表单数据实例的映射一起使用(为了简单起见,目前只有一个字符串),如下所示: @ManagedBean(name="employeeBean") @SessionScoped p

我的jsf应用程序是这样设计的,通过单击菜单项,相应的页面将显示在新创建的选项卡中。选项卡上显示的页面有自己的表单元素&backingbean。 通常情况下,这很有效,但无法找到一种方法来解决同时使用同一表单的多个实例的情况,例如,同时打开更多的“添加新员工”选项卡。 我尝试将
@SessionScoped
托管bean与包含表单数据实例的
映射一起使用(为了简单起见,目前只有一个字符串),如下所示:

@ManagedBean(name="employeeBean")
@SessionScoped
public class EmployeeBean extends BaseManagedBean implements Serializable{

    private Map<String, String> fields = new HashMap<String, String>();

    private String formId;

    public void newForm(){
        this.formId=RandomStringUtils.randomAlphabetic(10);
        logger.debug("newForm: formId: " + formId);
        this.fields.put(formId, new String());
}
//... etc
}
上一个打开的选项卡实例可以很好地工作,但旧的不能。如果在较旧的选项卡上按了
commandLink
,则会提交正确的表单,并在还原视图阶段调用一次
getFormId
方法,但在my
EmployeeBean
中不会调用任何其他方法。 如果我使用固定的formId而不是随机的
#{employeebean.formId}
,那么总是提交第一个打开的选项卡的数据。(页面上具有相同id的多个表单)

我想我的组件树有问题。 我正在使用
Primefaces
TabView
组件(基于jquery),并在jquery javascript函数中向选项卡组件添加新选项卡

谁能告诉我我做错了什么?或者提出更好的解决问题的方法?处理这种情况的正确方法是什么


提前非常感谢

这里需要会话范围的bean吗?例如,您是否希望从其他页面访问bean内容?如果没有,那么您可以简单地将您的
EmployeeBean
请求范围限定。你不需要在你的
employeeBean
中有地图,你的
valuebindings
也可以更简单…

可能不是最好的解决方案,但我设法提交了我所有的标签。诀窍在于,我对所有表单使用相同的id,并将
PrimeFaces.ajax.AjaxRequest
替换为我自己的AjaxRequest,它总是发布当前表单(其中按下
CommandLink
),而不是第一个表单。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:p="http://primefaces.prime.com.tr/ui">

<div class="dataContainer clearfix">
<h:form id = "#{employeeBean.formId}">
    <h:inputText id="empField1" value="#{employeeBean.fields[employeeBean.formId]}" />
    <p:commandLink action="#{employeeBean.action}" value="Action" id="actionLink">
    </p:commandLink>
</h:form>
</div>  
</html>