Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.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/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
Java 清除JSF上的输出字段_Java_Jsf_Primefaces - Fatal编程技术网

Java 清除JSF上的输出字段

Java 清除JSF上的输出字段,java,jsf,primefaces,Java,Jsf,Primefaces,我在使用JSF和PrimeFaces时遇到了一个小问题。我有一个有两个s和两个s的表单。第一个的内容更新第二个,两个的内容更新为第二个。这两个都依赖于我的支持bean上的值。问题是,当第一个更改其值时,我无法清除 我尝试使用带有侦听器的清除当前显示实体的内容 下面是xhtml: 以及bailmentsController上第一个的侦听器: public void clearView(BailmentFamilies bf) { if (bf != null) { cu

我在使用JSF和PrimeFaces时遇到了一个小问题。我有一个有两个
s和两个
s的表单。第一个
的内容更新第二个,两个
的内容更新为第二个
。这两个
都依赖于我的支持bean上的值。问题是,当第一个
更改其值时,我无法清除

我尝试使用带有侦听器的
清除当前显示实体的内容

下面是xhtml:


以及bailmentsController上第一个
的侦听器:

public void clearView(BailmentFamilies bf) {
    if (bf != null) {
        current = new Bailments();
        current.setBailmentFamId(bf);
    }
}
在我的数据库中,每个baillment都被分配了一个baillmentfamily,这就是我使用两步过滤器的原因。第一个
列出所有可用的BailmentFamilies,第二个
显示所选BailmentFamilies的所有可用BailmentFamilies。
s显示所选寄存单的信息,这就是为什么我需要在BailmentFamily更改时清除这些信息


有人能提出另一种行动方案吗?因为这并没有被证明是有效的。非常感谢。

当第一个选择菜单的
标记的
呈现
属性中没有列出
时,您为什么希望
会被ajax更新?你需要

  • id
    属性分配给两个
    s

    <h:outputText id="text1" value="#{bundle.BailmentFamiliesLabel_bailmentFamCode}"/>
    <h:outputText id="text2" value="#{bundle.BailmentsLabel_bailmentCode}"/>
    

  • 当第一个选择菜单的
    标记的
    呈现
    属性中没有列出
    时,为什么希望
    进行ajax更新?你需要

  • id
    属性分配给两个
    s

    <h:outputText id="text1" value="#{bundle.BailmentFamiliesLabel_bailmentFamCode}"/>
    <h:outputText id="text2" value="#{bundle.BailmentsLabel_bailmentCode}"/>
    

  • 我刚刚解决了这个问题。结果是我必须清除实体中的所有值。也许很愚蠢,但其他开发人员可能会被这一点困住:

    我编辑了我的
    clearView()
    方法。这就是有效的代码:

    public void clearView(BailmentFamilies bf) {
        if (bf != null) {
            // Create a new empty object to recieve the new BailmentFamily
            current = new Bailments();
            current.setBailmentFamId(bf); // This property has to be kept. 
            // I pass it as parameter and reassigned it to the current entity. 
            // Otherwise, the <p:selectonemenu> will clear upon rendering because of the new call above.
        }
    
        // Set ALL displayed properties to null
        current.setBailmentCode(null);
        current.setDescription(null);
        current.setPurchasePrice(null);
    }
    
    public void clearView(bailmentbf){
    如果(bf!=null){
    //创建新的空对象以接收新的BailmentFamily
    当前=新托管();
    current.setBailmentFamId(bf);//必须保留此属性。
    //我将其作为参数传递,并将其重新分配给当前实体。
    //否则,由于上面的新调用,渲染时将清除。
    }
    //将所有显示的属性设置为空
    当前.setBailmentCode(空);
    current.setDescription(空);
    current.setPurchasePrice(空);
    }
    

    希望这对任何人都有帮助。

    我刚刚解决了这个问题。结果是我必须清除实体中的所有值。也许很愚蠢,但其他开发人员可能会被这一点困住:

    我编辑了我的
    clearView()
    方法。这就是有效的代码:

    public void clearView(BailmentFamilies bf) {
        if (bf != null) {
            // Create a new empty object to recieve the new BailmentFamily
            current = new Bailments();
            current.setBailmentFamId(bf); // This property has to be kept. 
            // I pass it as parameter and reassigned it to the current entity. 
            // Otherwise, the <p:selectonemenu> will clear upon rendering because of the new call above.
        }
    
        // Set ALL displayed properties to null
        current.setBailmentCode(null);
        current.setDescription(null);
        current.setPurchasePrice(null);
    }
    
    public void clearView(bailmentbf){
    如果(bf!=null){
    //创建新的空对象以接收新的BailmentFamily
    当前=新托管();
    current.setBailmentFamId(bf);//必须保留此属性。
    //我将其作为参数传递,并将其重新分配给当前实体。
    //否则,由于上面的新调用,渲染时将清除。
    }
    //将所有显示的属性设置为空
    当前.setBailmentCode(空);
    current.setDescription(空);
    current.setPurchasePrice(空);
    }
    
    希望这对任何人都有帮助。

    您也可以使用

    <input type="button" value="Reset Form" onclick="this.form.reset()" />
    
    
    
    这将重置表单值,但不会重置支持bean,因此如果您使用来自表单外部actionListener/action的表单数据,这种方法将不安全。

    您也可以使用

    <input type="button" value="Reset Form" onclick="this.form.reset()" />
    
    
    

    这将重置表单值,但不会重置支持bean,因此,如果您使用来自表单外部actionListener/action的表单数据,这种方法就不安全了。

    为什么您希望
    在第一个选择菜单的
    标记的
    呈现
    属性中没有列出,而
    却会被ajax更新?为什么您希望
    会被ajax更新当它们没有在第一个选择菜单的
    标记的
    render
    属性中列出时,我刚刚解决了这个问题。我将用答案编辑这个问题。我还忘了添加所有内容都在
    中,我假设OP问题中提供的所有组件都在
    中,因此得到了这个错误。关于问题的解决方法,请参考OP自己的答案。@LuiggiMendoza,现在很明显了。没有这一点信息,我相信OP已经清除了后面的值,但是视图没有反映出变化,我刚刚解决了这个问题。我将用答案编辑这个问题。我还忘了添加所有内容都在
    中,我假设OP问题中提供的所有组件都在
    中,因此得到了这个错误。关于问题的解决方法,请参考OP自己的答案。@LuiggiMendoza,现在很明显了。如果没有这一点信息,我相信OP已经清除了后面的值,但视图未能反映变化+1,请在将来的问题中尽量包含相关信息+1,请在将来的问题中尽量包含相关信息