在每个身体我有一个问题我正在使用selctOneMenu,在我选择其中一个替代方案后,服务器端的其他方法永远不会被触及,我不明白为什么
这是我的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>
这是我的豆子:
@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;
这是我的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;
}
}
答案 0 :(得分:0)
HY, 你的问题是:你没有在
中做转换器改变这个:
<p:selectOneMenu value="#{commandeActBeanc.modePayement}">
<f:selectItem itemLabel="--" itemValue="" />
<f:selectItems value="#{modePayementArtBean.modesPayementLista}"
var="mode" itemLabel="#{mode.intitule}" itemValue="#{mode}" />
</p:selectOneMenu>
使用:
<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>
然后你就像这样写下类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 "";
}
}}
并且为了完成你必须在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;
}
}
现在一切正常:)