[英]How to conect from one xhtml page to data in another page with Primefaces
I am sending some variables from an .xhtml page to a controller wich sends data to another page that has another controller that handles the data of that page i have tried to use the setters and getters.我正在将一些变量从 .xhtml 页面发送到一个控制器,该控制器将数据发送到另一个页面,该页面具有另一个处理该页面数据的控制器,我曾尝试使用 setter 和 getter。 the problem is that i dont really know to do with @PostConstruct.问题是我真的不知道与@PostConstruct 有什么关系。
XHTML file XHTML 文件
<h:form id="frmStart">
<p:growl id="growl" sticky="true" showDetail="true" />
<p:panel id="pnlDatos">
<p:dataTable id="tblObjeto" var="object"
value="#{parentControlador.listObjects}"
widgetVar="tblObjeto"
emptyMessage="No hay datos">
<f:facet name="header">
Objetos
</f:facet>
<p:column headerText="Contar" width="20">
<p:commandButton class="pi pi-list" id="openDialogContar" value="Ver"
action="#{parentControlador.FindItems(object)}"
/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
ParentControlador controller code ParentControlador 控制器代码
@Inject Item item;
public String FindItems(ObjectParent objectParent) {
String type="";
String result="";
//variable that i am going to send
ItemControlador itemControlador = new ItemControlador();
itemControlador.setCorte(objectParent);
try {
if(item.listarItemsA(objectParent.getCorte_id()).isEmpty()){
this.listaItems = item.listarItemsB(objectParent.getCorte_id());
type = "A";
}else{
this.listaItems = item.listarItemA(objectParent.getCorte_id());
type = "B";
}
this.objeto = objectParent;
result = type == "A"? "A.xhtml":"B.xhtml";
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error",
"The objectParent doesnt have items "+e.getMessage()));
}
return result;
}
This is the controller that handles the view for "A.xhtml", "B.xhtml"Item这是处理“A.xhtml”、“B.xhtml”项目视图的控制器
@PostConstruct
private Parent parent;
public void init() {
//From what i see, thos is ejecuted when a .xhtml page is using the controller to retrieve the dataTable
//
if(item.listarItemsB(objectParent.getCorte_id()).isEmpty()){
this.listaObjetos = item.listarItemA(objectParent.getCorte_id());
}else{
this.listaObjetos = item.listarItemsA(objectParent.getCorte_id());
}
}
public Parent getCorte() {
return corte;
}
public void setCorte(Parent parent) {
this.parent = parent;
}
how do i send data form an xhtml view that handles one controller X to view the data, send to another xhtml page that uses another controller Y, and show in the other page that uses Y controller to view the data of the data sent.我如何从处理一个控制器 X 的 xhtml 视图发送数据以查看数据,发送到另一个使用另一个控制器 Y 的 xhtml 页面,并在使用 Y 控制器的另一个页面中显示发送的数据的数据。
In case you need to make some data shared between two .xhtml
views, you may put your data in a @SessionScoped
controller which will have the same state among both views within the same browser-session and is visible to both views.如果您需要在两个.xhtml
视图之间共享一些数据,您可以将数据放在@SessionScoped
控制器中,该控制器在同一浏览器会话中的两个视图之间具有相同的状态,并且对两个视图都可见。 Simply from page1.xhtml
submit your data to the @SessionScoped
controller and access it from page2.xhtml
只需从page1.xhtml
提交您的数据到@SessionScoped
控制器并从page2.xhtml
访问它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.