【发布时间】:2014-08-06 08:17:31
【问题描述】:
我正在使用 Primefaces 5。
我想在选择时调用监听器,监听器被调用但它返回一个空对象;
我的 JSF 页面中有以下内容
<ui:define name="page-content">
<h:form prependId="false">
<p:commandButton image="back" ajax="false" immediate="true" style="margin-right:20px;" value="#{phasemsgs['navigation.back']}" action="/boo/viewMesTaches.xhtml"/>
<p:panel header="#{phasemsgs['tache.title']} Details" style="margin-top:10px">
<p:messages />
<h:panelGrid id="detail" columns="2" styleClass="grid" columnClasses="label,value">
<h:outputText value="#{phasemsgs['tache.nomtache.title']}:" />
<h:inputText id="phase_nomtache" value="#{TacheComponent.tache.nomtache}" required="false" label="phase_nomtache" />
<h:outputText value="Projet :*" />
<h:selectOneMenu id="selectProjet"
value="#{ProjetComponent.projet.idprojet}" required="false">
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{ProjetComponent.listProjets()}"
var="projet" itemValue="#{projet.idprojet}"
itemLabel="#{projet.nomprojet}" />
<p:ajax listener="#{ProjetComponent.onProjetChange()}"
update="selectPhase" />
<f:converter converterId="entityConverter" />
</h:selectOneMenu>
<h:outputText value="Phase :*" />
<h:selectOneMenu id="selectPhase"
value="#{TacheComponent.tache.phase.idphase}" required="false">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{ProjetComponent.listPhases}" var="phase"
itemValue="#{phase}" itemLabel="#{phase.typephase}" />
<f:converter converterId="entityConverter" />
</h:selectOneMenu>
</h:panelGrid>
这是我的组件中的 onProjetChange 方法:
@Scope("session")
@Component("ProjetComponent")
public class ProjetComponentImpl implements ProjetComponent {
private Projet projet;
List<Phase> listPhases;
@Autowired
private ProjetDAO projetDAO;
getters and setters ..
public ProjetComponentImpl() {
}
@PostConstruct
public void init() {
//initialize the data here
this.projet=new Projet();
this.listPhases=new ArrayList<Phase>();
}
public void onProjetChange() {
if(projet !=null && !projet.equals(""))
{
listPhases = new ArrayList<Phase> (projet.getPhases());
System.out.println("onProjetChange Clause if:" + projet.getNomprojet());
}
else{
listPhases = new ArrayList<Phase>();
System.out.println("onprojetChange else:"+projet.getNomprojet());
}
这是堆栈跟踪:
onProjetChange Clause if:null
这是一个截图:
【问题讨论】:
标签: jquery ajax jsf jsf-2 primefaces