Primefaces Chips组件未将项目添加到列表

时间:2019-04-29 22:06:51

标签: jsf primefaces

它不会更新managebean中的列表模型的Chips组件使用下一个教程chips u,我正在尝试更新ap:chips组件的模型,正在使用Apache tomcat 9和primefaces 6.2,我已经添加了使用PostConstruct在此List中的某些数据,该数据列表显示在组件中,但是当在视图中添加了某些项目时,在模型管理bean中没有修改任何项目,请在看到记录器之后,items.size()保持不变,该组件视图中的行为会按预期做出反应。在Windows计算机上,它按预期工作。

我的xhtml

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:cmp="http://xmlns.jcp.org/jsf/composite/cmp">

<h:form id="formChips">
    <p:outputLabel for="items" value="Items: " /><br/>
    <p:chips id="items" value="#{beanChipsViewer.items}" inmediate="true"  >
        <p:ajax event="itemSelect" listener="#{beanChipsViewer.chipsSelect}" update=":itemList chips"/>
        <p:ajax event="itemUnselect" listener="#{beanChipsViewer.chipsDeselect}" update=":itemList chips"/>
        <p:ajax event="change" process="@this" update="chips" delay="300" />
        <p:ajax event="valueChange" process="@this" update="chips" delay="300" />
        <p:ajax event="click" process="@this" update="chips" delay="300" listener="#{beanChipsViewer.mostrar}" />
        <p:ajax event="mousedown" process="@this" update="chips" delay="300" />
        <p:ajax event="mouseup" process="@this" update="chips" delay="300" />
    </p:chips>
    <br/>
    <p:commandButton value="Save" icon="ui-icon-check" update=":itemList" action="#{beanChipsViewer.agregar()}"
        actionListener="#{beanChipsViewer.mostrar}"
    />
    <br/>
</h:form>
<br/>

<p:outputPanel id="itemList">
    <p:repeat  value="#{beanChipsViewer.items}" var="item">
        <h:outputText value="#{item}"/>
        <br/>
    </p:repeat>
</p:outputPanel>

<h:panelGroup id="chips">
    <h:outputText value="#{beanChipsViewer.items}" />
</h:panelGroup>

<br/>

这是编码的托管bean:

  @Named
@ViewScoped
public class BeanChipsViewer implements Serializable {

    private String itemSelected;
    private String itemUnselected;
    private static final Logger logger = LoggerFactory.getLogger(BeanChipsViewer.class);


    @PostConstruct
    public void init(){
        for(int i=0;i<20;i++)
            items.add("etiqueta "+i);
    }

    private List<String> items = new ArrayList<String>();

    public List<String> getItems() {
        return items;
    }

    public void setItems(List<String> items) {
        this.items = items;
    }

    public  void agregar(){
        logger.info("Entra " +items.size());
        items.add("nitro");
        logger.info("zize after intro" +items.size());
        UtilsPrimefaces.executeUpdatePF("itemList");
    }

    public void mostrar(){
        logger.info("Entra mostrar");
        for(String m:items){
            logger.info("chipItem "+ m);
        }
    }

    public void chipsSelect(SelectEvent e){
        logger.info("chip seleted"+e.getObject().toString());
        this.setItemSelected(e.getObject().toString());
        items.add(e.getObject().toString());
        logger.info("items size afteR chipselected "+ items.size());
    }


    public void chipsDeselect(UnselectEvent e){
        logger.info("chip deselect"+e.getObject().toString()+" "+items.size());
        this.setItemUnselected(e.getObject().toString());

    }

    public void phaseListener(PhaseEvent e){
        List<FacesMessage> messages = e.getFacesContext().getMessageList();
        System.out.println(messages.size());
    }

1 个答案:

答案 0 :(得分:1)

我必须使用下一个导入

import javax.faces.view.ViewScoped;
import javax.inject.Named;

我正在将@ManageBean与CDI混合