提交表单时,JSF动态渲染组件的值变为空 [英] JSF Dynamic Rendered Component's Value becomes null when the form is submitted

查看:135
本文介绍了提交表单时,JSF动态渲染组件的值变为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF页面,它根据使用键盘ajax listner的下拉菜单的值,呈现文本字段。动态渲染完成。但问题是一旦我提交表单,该文本框的绑定值不会被绑定,而不是被显示为null。

I have a JSF page which renders a text field depending on the value of a drop down using primefaces ajax listner. The dynamic rendering is done fine. but the problem is once I submit the form the the bound value of that textfield doesn't get bound instead it is shown as null.

这是我的JSF的一部分

this is the part of my JSF only the necessary fields are included here

<h:panelGroup id="textPanel" >
<h:form id="main" prependId="false"> 
<h:outputText value="WorkFlow ID:" />  
<h:selectOneMenu id="workFlows"  value="#{workFlowSelectionController.selectedWorkFlowId}" >
<p:ajax event="change" listener="#{workFlowSelectionController.dropDownChange}"  update="textPanel"/>
<f:selectItems value="#{workFlowSelectionController.allActiveworkFlows}"/>
</h:selectOneMenu> 
<p:inputText  value="#{workFlowSelectionController.texField}" rendered="#{workFlowSelectionController.textfieldVisibility}"/>
<p:commandButton ajax="false"  value="Next"   action="#{workFlowSelectionController.addWorkFlowselectionDetails}"/>  
</h:form>
</h:panelGroup>    

这是我的托管bean

this is my managed bean

@ManagedBean
@RequestScoped
public class WorkFlowSelectionController {
private boolean textfieldVisibility = false;
private String texField;

public void dropDownChange() {
    logger.info("WorkFlowSelectionController.dropDownChange() entered");



    if (selectedWorkFlowId != null) {

        if (selectedWorkFlowId.equals("-1")) {
            textfieldVisibility = true;
            operationListStatus = false;


        } else {
            textfieldVisibility = false;
            operationListStatus = true;

        }
    } else {
        textfieldVisibility = false;
        operationListStatus = true;

    }
public void addWorkFlowselectionDetails() throws CloneNotSupportedException {



    System.out.println("Selected Value of Text Field is" + texField);


}
public String getTexField() {
    return texField;
}

public void setTexField(String texField) {
    this.texField = texField;
}
}

我没有包括支持的下拉列表豆。我只需要一个想法,我在这里做错了,如果我删除文本框的渲染属性,它的工作正常。

i haven't included the dropdown code of the backing bean. i just need an idea of what i am doing wrong here if i remove the rendered attribute of the textfield it works fine.

谢谢

推荐答案

将bean放在视图范围而不是请求范围内。在每个HTTP请求上重新创建一个请求范围。当您提交表单时,布尔属性将默认为false,因此,将不会处理提交的值。

Put the bean in the view scope instead of request scope. A request scoped is recreated on every single HTTP request. The boolean property will default to false again whenever you submit the form, so the submitted value won't be processed then.

@ManagedBean
@ViewScoped
public class WorkFlowSelectionController {
    //
}

只要你(ajax-)通过返回 null void与同一视图进行交互,视图作用域bean就会生存 from action(listener)methods。

A view scoped bean will live as long as you're (ajax-) interacting with the same view by returning null or void from action(listener) methods.

这篇关于提交表单时,JSF动态渲染组件的值变为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆