无法使用 p:dataTable 将列表作为参数传递给 p:commandButton
Can´t pass List as parameter to p:commandButton using p:dataTable
有人帮忙吗...
我正在尝试将 list
作为参数传递给 p:dataTable
中的 p:commandButton
。它总是 null
.
这有什么问题吗?
提前致谢!
屏幕组件:
<h:form id="form-upload" enctype="multipart/form-data">
<div class="">
<h:outputText value="Foram encontradas as seguintes restrições:" />
<br /> <br />
<p:dataTable var="restricao" id="listaRestricoes"
value="#{decompDecisaoRestricoesController.listView}">
<p:inputText value="#{restricao.id}" type="hidden" />
<p:column headerText="Restrição">
<h:outputText value="#{restricao.nome}" />
<p:selectOneRadio id="comentar"
value="#{restricao.comentar}" layout="custom">
<f:selectItem itemValue="sim" />
<f:selectItem itemValue="nao" />
</p:selectOneRadio>
</p:column>
<p:column headerText="Comentar">
<p:radioButton for="comentar" itemIndex="0" />
</p:column>
<p:column headerText="Descomentar">
<p:radioButton for="comentar" itemIndex="1" />
</p:column>
</p:dataTable>
</div>
<div class="button-group">
<p:commandButton icon="ui-icon-circle-triangle-e"
value="Executar" widgetVar="uploadButton"
action="#{decompDecisaoRestricoesController.chamaService(listaRestricoes)}" />
</div>
</h:form>
控制者:
@Named
@RequestScoped
public class DecompDecisaoRestricoesController implements Serializable {
private static final long serialVersionUID = -6252355181831338279L;
@Inject
private DecompDecisaoRestricoesService service;
private List<RestricaoDecomp> listView;
public List<RestricaoDecomp> getListView() {
return listView;
}
public void setListView(List<RestricaoDecomp> listView) {
this.listView = listView;
}
public void onLoad() {
listView = service.listaRestricoesBanco();
}
public void chamaService(List<RestricaoDecomp> lista) {
service.executar(lista);
}
}
和服务:
@Stateless
public class DecompDecisaoRestricoesService {
@Inject
RestricaoDecompDAO restricaoDecompDAO;
private Logger logger = LoggerFactory.getLogger(this.getClass());
public void executar(List<RestricaoDecomp> lista) {
for (RestricaoDecomp restricao : lista) {
logger.info("NOME: " + restricao.getNome());
logger.info("COMENTAR: " + restricao.getComentar());
}
}
public List<RestricaoDecomp> listaRestricoesBanco() {
List<RestricaoDecomp> lista = new ArrayList<RestricaoDecomp>();
lista = restricaoDecompDAO.listAll();
return lista;
}
}
渲染时,列表显示在视图中。但是在提交时,它只发送 null
.
做到了!
该 bean 是 RequestScoped
,因此,在请求之后,它只是丢弃了列表值。
将其更改为 ViewScoped
瞧!提交后列表值在那里,字段发生变化。
在那之后,我只是在提交后清理了view
。像这样:
<p:commandButton icon="ui-icon-circle-triangle-e" onsuccess="window.location.reload(); ..."
=)
有人帮忙吗...
我正在尝试将 list
作为参数传递给 p:dataTable
中的 p:commandButton
。它总是 null
.
这有什么问题吗? 提前致谢!
屏幕组件:
<h:form id="form-upload" enctype="multipart/form-data">
<div class="">
<h:outputText value="Foram encontradas as seguintes restrições:" />
<br /> <br />
<p:dataTable var="restricao" id="listaRestricoes"
value="#{decompDecisaoRestricoesController.listView}">
<p:inputText value="#{restricao.id}" type="hidden" />
<p:column headerText="Restrição">
<h:outputText value="#{restricao.nome}" />
<p:selectOneRadio id="comentar"
value="#{restricao.comentar}" layout="custom">
<f:selectItem itemValue="sim" />
<f:selectItem itemValue="nao" />
</p:selectOneRadio>
</p:column>
<p:column headerText="Comentar">
<p:radioButton for="comentar" itemIndex="0" />
</p:column>
<p:column headerText="Descomentar">
<p:radioButton for="comentar" itemIndex="1" />
</p:column>
</p:dataTable>
</div>
<div class="button-group">
<p:commandButton icon="ui-icon-circle-triangle-e"
value="Executar" widgetVar="uploadButton"
action="#{decompDecisaoRestricoesController.chamaService(listaRestricoes)}" />
</div>
</h:form>
控制者:
@Named
@RequestScoped
public class DecompDecisaoRestricoesController implements Serializable {
private static final long serialVersionUID = -6252355181831338279L;
@Inject
private DecompDecisaoRestricoesService service;
private List<RestricaoDecomp> listView;
public List<RestricaoDecomp> getListView() {
return listView;
}
public void setListView(List<RestricaoDecomp> listView) {
this.listView = listView;
}
public void onLoad() {
listView = service.listaRestricoesBanco();
}
public void chamaService(List<RestricaoDecomp> lista) {
service.executar(lista);
}
}
和服务:
@Stateless
public class DecompDecisaoRestricoesService {
@Inject
RestricaoDecompDAO restricaoDecompDAO;
private Logger logger = LoggerFactory.getLogger(this.getClass());
public void executar(List<RestricaoDecomp> lista) {
for (RestricaoDecomp restricao : lista) {
logger.info("NOME: " + restricao.getNome());
logger.info("COMENTAR: " + restricao.getComentar());
}
}
public List<RestricaoDecomp> listaRestricoesBanco() {
List<RestricaoDecomp> lista = new ArrayList<RestricaoDecomp>();
lista = restricaoDecompDAO.listAll();
return lista;
}
}
渲染时,列表显示在视图中。但是在提交时,它只发送 null
.
做到了!
该 bean 是 RequestScoped
,因此,在请求之后,它只是丢弃了列表值。
将其更改为 ViewScoped
瞧!提交后列表值在那里,字段发生变化。
在那之后,我只是在提交后清理了view
。像这样:
<p:commandButton icon="ui-icon-circle-triangle-e" onsuccess="window.location.reload(); ..."
=)