简体   繁体   English

Primefaces SelectOneMenu阻止其他方法

[英]Primefaces SelectOneMenu Blocks the other method

hi every body i have a problem i'm using a selctOneMenu that after i choose one of the alternativs the other methods on the server side is never trigered and i ca't figure out why 嗨,大家好,我有一个问题,我正在使用selctOneMenu,在我选择了一个替代方法之后,服务器端的其他方法再也不会触发了,我也不知道为什么

here is my jsf code snippets 这是我的jsf代码段

....
...
<p:panel style="height:85px;">

                        <h:outputLabel
                            style="font: italic;font-family:serif;font-weight: lighter;font-size: x-large;">
                                Mode de Payement:   
                    </h:outputLabel>

                        <p:selectOneMenu value="#{commandeActBeanc.modePayement}">
                            <f:selectItem itemLabel="--" itemValue="" />
                            <f:selectItems value="#{modePayementArtBean.modesPayementLista}" 
                                var="mode" itemLabel="#{mode.intitule}" itemValue="#{mode}" />
                        </p:selectOneMenu>
                    </p:panel>
                </h:panelGrid>
                <br />

                <p:contextMenu for="articles" widgetVar="cMenu">
                    <p:menuitem value="Edit Cell" icon="ui-icon-search"
                        onclick="PF('BCTable').showCellEditor();return false;" />
                    <p:menuitem value="Hide Menu" icon="ui-icon-close"
                        onclick="PF('cMenu').hide()" />
                </p:contextMenu>

                <p:dataTable id="articles" var="art" rendered="true"
                    paginator="true" rows="10" style="width:99%;padding-left:8px;"
                    value="#{commandeActBeanc.mediumArticleSuppModel}" editable="true"
                    editMode="cell" widgetVar="BCTable"
                    rowKey="#{art.idArtileBoncommande}"
                    selection="#{commandeActBeanc.selectedArticlesSupp}">

                    <f:facet name="header">
                            Commande n° #{commandeActBeanc.cmd.idBoncommande}
                    </f:facet>

                    <p:ajax event="cellEdit" listener="#{commandeActBeanc.onCellEdit}"
                        update=":form:messages,:@this,:form:totaleTtc,:form:totaleHt,:form:totaleTva" />

                    <p:column selectionMode="multiple" style="width:2%" />
                    <p:column headerText="code.Art" style="width:15%">

                            #{art.codeArticle} 

                    </p:column>

                    <p:column headerText="Libelle.Art" style="width:15%">

                                 #{art.referenceArticle}

                    </p:column>

                    <p:column headerText="P.U en TTC" style="width:15%">
                        #{art.prixUnitTtc}
                    </p:column>

                    <p:column headerText="Quantité" style="width:15%">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{art.quantite}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText value="#{art.quantite}" style="width:96%"
                                    label="Quantite" />

                            </f:facet>
                        </p:cellEditor>
                    </p:column>

and here is my bean: 这是我的豆子:

@Component("commandeActBeanc")
@SessionScoped
public class CommandeActionBean {

    @Autowired
    private transient ICommandeDao commandeDAO;
    @Autowired
    private transient IPcArticleBoncommandeDao articleCommandeDAO;
    @Autowired
    private transient IProduitDao articleDAO;

    private Integer idBoncommande;
    private Agent agent;
    private ModePayement modePayement;
    private String numero;
    private Boolean isValide;
    private Boolean isSolde;
    private Boolean isImprime;
    private Boolean isSaved;
    private Date dte;

this is my ModPayemenActionBean 这是我的ModPayemenActionBean

@Component("modePayementArtBean")
@SessionScoped
public class ModePayementActionBean {

    @Autowired
    IModePayementDao modePayementDao;
    private String intitule;
    private List<ModePayement> modesPayementLista= new ArrayList<ModePayement>();
    /*-----------------------------------Setters et Getters--------------------------------*/


    public IModePayementDao getModePayementDao() {

        return modePayementDao;
    }

    public ModePayementActionBean() {

    }

    public List<ModePayement> getModesPayementLista() {
        modesPayementLista= new ArrayList<ModePayement>();
        modesPayementLista.addAll(getModePayementDao().findAll());
        for (int i=0;i<modesPayementLista.size();i++){
            System.out.println(modesPayementLista.get(i));
        }
        return modesPayementLista;
    }

    public void setModesPayementLista(List<ModePayement> modesPayementLista) {
        this.modesPayementLista = modesPayementLista;
    }

    public void setModePayementDao(IModePayementDao modePayementDao) {
        this.modePayementDao = modePayementDao;
    }

    public String getIntitule() {
        return intitule;
    }

    public void setIntitule(String intitule) {
        this.intitule = intitule;
    }

}

Hy, your problem is: you have not do a convertor in 嗨,您的问题是:您没有在

change this: 改变这个:

<p:selectOneMenu value="#{commandeActBeanc.modePayement}">
                        <f:selectItem itemLabel="--" itemValue="" />
                        <f:selectItems value="#{modePayementArtBean.modesPayementLista}" 
                            var="mode" itemLabel="#{mode.intitule}" itemValue="#{mode}" />
                    </p:selectOneMenu>

with: 与:

<p:selectOneMenu value="#{commandeActBeanc.modePayement}" converter="modePayementConvertor">
                        <f:selectItem itemLabel="--" itemValue="" />
                        <f:selectItems value="#{modePayementArtBean.modesPayementLista}" 
                            var="mode" itemLabel="#{mode.intitule}" itemValue="#{mode}" />
                    </p:selectOneMenu>

and after that you mast write class modePayementConvertor like this: 然后,您像这样编写桅杆类class modePayementConvertor:

@FacesConverter(value = "modePayementConvertor", forClass = IModePayementDao.class)
public class ModePayementConverter implements Converter {
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
    Integer target = new Integer(arg2);
/**this use hibernate change it if u like **/
    Session session = ConnectionDb.getInstance().openSession();
    IModePayementDao modePayement= (IModePayementDao) session.get(IModePayementDao.class, target);
    session.close();
    return modePayement;
}

@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
    try {
        return ((IModePayementDao) arg2).getId().toString();
    }
    catch (NullPointerException ex) {
        return "";
    }
}}

and for finish you must @Override the methode equal in IModePayementDao like this: 最后,您必须像这样在IModePayementDao中@Override等于方法:

/**
 * @see java.lang.Object#equals(java.lang.Object)
 */
@Override
public boolean equals(Object obj) {

    if (obj instanceof IModePayementDao ) {

        if (((IModePayementDao ) obj).getId().equals(this.id)) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }

}

Now all is ok :) 现在一切都好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM