我有一个数据表,我可以动态添加行,点击添加按钮。
<p:dataTable id="ListTable" styleClass="hide-column-names"
value="#{sManagedBean.View.pList}"
var="p" rowIndexVar="rowIndex">
<p:column>
<p:inputText id="pInput" required="#{not empty param[saveButton.clientId]}" value="#{p.name}" />
</p:column>
<p:column>
<p:selectOneMenu id="pSs" value="#{p.sp}">
<p:ajax update="pComplete" global="false" />
<f:selectItem itemLabel="Select" itemValue="0"/>
<f:selectItems value="#{sManagedBean.pList}" var="sp" itemValue="#{sp.id}" itemLabel="#{sp.title}" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:autoComplete id="pComplete" value="#{p.ptitle}" required="#{not empty param[saveButton.clientId]}" completeMethod="#{sManagedBean.pComplete}" global="false" minQueryLength="3">
<p:ajax event="query" global="false" />
<f:attribute name="filter" value="#{p.sp}" />
</p:autoComplete>
</p:column>
<p:column>
<p:commandLink value="Delete" id="delete"
actionListener="#{sManagedBean.removeFromList}"
update="ListTable pSs"
rendered="#sManagedBean.oView.ptList.size()>'1'}">
<f:param name="rowToRemove" value="#{rowIndex}" />
</p:commandLink>
</p:column>
</p:dataTable>
<h:outputText/>
<p:commandLink id="addPLink" value="Add"
style="font-weight:bold;"
actionListener="#{sManagedBean.AddP}"
update="ListTable growlQ" global="false">
<h:graphicImage value="../images/addbutton.jpg" />
</p:commandLink>
托管Bean
public List<String> pComplete(int query) {
FacesContext context = FacesContext.getCurrentInstance();
int sId = Integer.parseInt(UIComponent.getCurrentComponent(context).getAttributes().get("filter").toString());
System.out.println("s " + sId);
Session session = null;
List<String> result = null;
try {
session = hibernateTemplate.getSessionFactory().openSession();
result = session.createSQLQuery("select title from pb where title like : alphabets and sId =:sId").setString("alphabets", query + "%").setInteger("sId", sId + 1).list();
} catch (Exception e) {
log.warn("FL Warning", e);
}
return result;
}
但通过自动填充传递的值始终为零。
我无法获得相应行的selectone菜单的值。
答案 0 :(得分:1)
这应该做的工作:
<p:column>
<p:selectOneMenu id="pSs" value="#{p.species}">
<p:ajax update="pComplete" global="false" />
<f:selectItem itemLabel="Select" itemValue="0"/>
<f:selectItems value="#{sManagedBean.pList}" var="sp" itemValue="#{sp.id}" itemLabel="#{sp.title}" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:autoComplete id="pComplete" value="#{p.ptitle}" required="#{not empty param[saveButton.clientId]}" completeMethod="#{sManagedBean.pComplete}" minQueryLength="3">
<p:ajax event="query" global="false" />
<f:attribute name="filter" value="#{p.species}" />
</p:autoComplete>
</p:column>
答案 1 :(得分:0)
我得到了答案,我在selectone菜单之间添加了ajax
<p:ajax event="change" update="pComplete"/>