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
Jsf 2 JSF2.0输出文本呈现选择菜单_Jsf 2_Primefaces_Selectonemenu - Fatal编程技术网

Jsf 2 JSF2.0输出文本呈现选择菜单

Jsf 2 JSF2.0输出文本呈现选择菜单,jsf-2,primefaces,selectonemenu,Jsf 2,Primefaces,Selectonemenu,我正在使用JSF-2,当h:selectOneMenu值更改为“A”时,我想显示一个Outputtext,但它不起作用: 以下是视图: <p:column> <p:selectOneMenu id="type" value="#{Controller.typeR}" style="width:100px;"> <f:selectItem itemLabel="--Selectionner--" itemValue="-1" /> <f:

我正在使用JSF-2,当h:selectOneMenu值更改为“A”时,我想显示一个Outputtext,但它不起作用:

以下是视图:

 <p:column>
<p:selectOneMenu id="type"
value="#{Controller.typeR}" style="width:100px;">
    <f:selectItem itemLabel="--Selectionner--" itemValue="-1" />
    <f:selectItem itemLabel="A" itemValue="1" />
    <f:selectItem itemLabel="B" itemValue="2" />
    <f:selectItem itemLabel="C" itemValue="3" />
<p:ajax update="test"
 listener="#{Controller.handleTypeChange}" />
</p:selectOneMenu>
 </p:column>
 <p:column>
  <h:outputText id ="test" value="A OK :" rendered="#{Controller.typeAOk}" />
 </p:column>
任何帮助都将不胜感激

由于
#{Controller.typeAOk}
似乎是错误的,您的outputText将不会是生成的html页面的一部分,因此无法对其进行更新

在这种情况下,您需要将输出文本包装到另一个组件中,然后更新始终呈现的组件。以下是一个例子:

<p:column>
    <p:outputPanel id="test">
        <h:outputText  value="A OK :" rendered="#{Controller.typeAOk}" />
    </p:outputPanel>
</p:column>

再次声明:只能更新渲染组件

以下是我用来测试解决方案的完整代码(请注意,您也可以使用panelGroup):


ManagedBean

 @SuppressWarnings("serial")
 @ManagedBean(name = "Controller")
 @ViewScoped
 public class NoIe{

 public void handleTypeChange(){        
        if (typeR.equals("1")) {
            setTypeAOk(true);
            System.out.print(typeAOk);
             }}

    //Getter and Setter
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class ViewMBean implements Serializable {

    private Integer id;

    private List<SimpleBean> list;

    @PostConstruct
    public void setup() {
        list = new ArrayList<SimpleBean>();
        list.add(new SimpleBean(11, "A"));
        list.add(new SimpleBean(22, "B"));
        list.add(new SimpleBean(33, "C"));
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public List<SimpleBean> getList() {
        return list;
    }

}
import java.io.Serializable;
导入java.util.ArrayList;
导入java.util.List;
导入javax.annotation.PostConstruct;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
@ManagedBean
@视域
公共类ViewMBean实现了可序列化{
私有整数id;
私人名单;
@施工后
公共作废设置(){
列表=新的ArrayList();
添加(新SimpleBean(11,“A”);
添加(新SimpleBean(22,“B”);
增加(新SimpleBean(33,“C”);
}
公共整数getId(){
返回id;
}
公共无效集合id(整数id){
this.id=id;
}
公共列表getList(){
退货清单;
}
}

thank you@Daniel,我尝试了你的解决方案,但要么不起作用:(很好,谢谢。如果我想对a的所有组件都这样做?它试图将行中的所有列包装在panelGroup中,但不起作用是datatable或panelgrid中的列吗?它们在panelgrid中
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class ViewMBean implements Serializable {

    private Integer id;

    private List<SimpleBean> list;

    @PostConstruct
    public void setup() {
        list = new ArrayList<SimpleBean>();
        list.add(new SimpleBean(11, "A"));
        list.add(new SimpleBean(22, "B"));
        list.add(new SimpleBean(33, "C"));
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public List<SimpleBean> getList() {
        return list;
    }

}