我已经实施了以下选择列表:
<p:pickList id="pickList" value="#{reportConfiguratorBean.dualListVars}" var="cRVariable" itemValue="#{cRVariable}" itemLabel="#{cRVariable.varName}" converter="#{cRImageTypeConverter}" immediate="true" rendered="true" >
<f:facet name="sourceCaption">Available Variables</f:facet>
<f:facet name="targetCaption">Associated Variables</f:facet>
</p:pickList>
<f:facet name="footer">
<p:commandButton id='varassociate' action="#{reportConfiguratorBean.setAssocImTypVariables()}" value='Associate' process="@this,pickList" />
</f:facet>
选择列表已正确填充(使用数据库中的 getAssocImTypVariables())。但我的问题是我无法捕获用户更改的选项列表值会更改源列表和目标列表。我正在尝试使用 commandButton 方法“setAssocImTypVariables”来捕获更改,如下所示:
public void setAssocImTypVariables() {
System.out.println(">>>>>>>>>>>>>>> entered");
List<CRVariable> sourceVariables = this.dualListVars.getSource();
List<CRVariable> targetVariables = this.dualListVars.getTarget();
System.out.println(dualListVars.getSource());
System.out.println(dualListVars.getTarget());
for (CRVariable sourceVariable:sourceVariables) {
System.out.println(">>>>>>>>>>>>> I am a source variable: " + sourceVariable.getVarName());
}
for (CRVariable targetVariable:targetVariables) {
System.out.println(">>>>>>>>>>>>> I am a target variable: " + targetVariable.getVarName());
}
}
因此,例如,如果我有一个带有 INITIAL source = (Obj1,Obj2,Obj3,Obj5,Obj7) 和 target = (Obj4,Obj6) 的选项列表,我将“Obj1”从源移动到目标但在我的控制台中我得到:
--------- 输入 [] []
所以我的 dualListVars(源和目标)没有填充!我有两个用于源和目标的空列表...
所以我的方法不能感知选项列表的变化......有什么想法吗?我是 java + primefaces 的新手,所以它可能是非常基本的东西:(
我还附上了getAssocImTypesOnLoad()方法:
public void getAssocImTypesOnLoad() {
Long imTypeId = Long.parseLong(virtualId);
List<CRVariable> source;
List<CRVariable> target;
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try
{
tx = session.beginTransaction();
String hq3 = "select distinct v from CRVariable v join v.crimagetypes t where t.id in (:itid)";
Query query3 = session.createQuery(hq3);
query3.setParameter("itid",imTypeId);
target = query3.list();
String hq4 = "select v FROM CRVariable v WHERE v.id not in (" +
"select distinct v1.id " +
"from CRVariable v1 " +
"join v1.crimagetypes t2 " +
"where t2.id in (:itid))";
Query query4 = session.createQuery(hq4);
query4.setParameter("itid",imTypeId);
source = query4.list();
dualListVars = new DualListModel<CRVariable>(source, target);
tx.commit();
}
catch (Exception e)
{
if (tx != null)
{
e.printStackTrace();
}
}
finally
{
session.close();
}
}