2015-07-20 50 views
0

我想知道我可以更改视图,因为一个bean,这是我的代码:Primefaces改变看法,因为一个Bean

principal.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui"> 

    <h:head> 
     <link rel="shortcut icon" type="image/x-icon" href="/resources/images/logoconsorcio.ico"/> 
     <f:facet name="first"> 
      <h:outputStylesheet name="css/default.css"/> 
      <h:outputScript name="scripts/scripts.js" /> 
      <title>Consorcio JM</title> 
     </f:facet> 
    </h:head> 
    <h:body> 
     <p:layout fullPage="true"> 
      <ui:include src="/pages/main/session_time_out.xhtml"/> 
      <!-- Header Panel--> 
      <p:layoutUnit position="north" size="40" resizable="true" closable="true" 
          collapsible="true" collapseSize="20"> 
       <ui:include src="/pages/main/header.xhtml" /> 
      </p:layoutUnit> 
      <!-- Tree Panel--> 
      <p:layoutUnit position="west" size="205" collapsible="true" header="Menu"> 
       <ui:include src="/pages/main/page_menu.xhtml" /> 
      </p:layoutUnit> 
      <!-- Content Panel--> 
      <p:layoutUnit id="idCenterLayout" position="center" > 
       <p:outputPanel id="idCentroPagina"> 
        <ui:include src="#{menuBean.paginaCentral}"/> 
       </p:outputPanel> 
      </p:layoutUnit> 
     </p:layout> 
    </h:body> 

#{menuBean.paginaCentral}

我把路径视为/pages/logistica/movimientos/orden_ingreso/orden_ingreso.xhtml

orden_ingreso.xhtml

<ui:composition 
xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui" > 

<h:form id="idFormOrdenIngreso" onkeypress="if (event.keyCode == 13) { return false; }"> 
    <p:growl id="idGrowlOI" showDetail="true" life="2500" for="keyOrdenIngreso" globalOnly="true"/> 
    <p:panel header="Orden de Ingreso" styleClass="texto-panel"/> 
    <ui:include src="/pages/logistica/movimientos/orden_ingreso/toolbar_orden_ingreso.xhtml"/> 
    <ui:include src="#{ordenIngresoBean.pathBodyOrdenIngreso}"/> 
</h:form> 
</ui:composition> 

OrdenIngresoBean.java

@ManagedBean(name = "ordenIngresoBean") 
@SessionScoped 
public class OrdenIngresoBean implements Serializable { 
private static final long serialVersionUID = 1L; 
private final String strBusiness = "OrdenIngresoBO"; 
private String pathBodyOrdenIngreso; 
private OrdenIngresoBO ordenIngresoBO; 
private OrdenIngresoUtil oiu; 
private OrdenIngresoDTO oiVista; 
private final HttpServletRequest httpServletRequest; 
private final FacesContext facesContext; 
private final Empresa empresa; 
private final UsuarioLO usuario; 


public OrdenIngresoBean() { 
    facesContext = FacesContext.getCurrentInstance(); 
    httpServletRequest = (HttpServletRequest)facesContext.getExternalContext().getRequest(); 
    empresa = (Empresa)httpServletRequest.getSession().getAttribute("empresaSession"); 
    usuario = (UsuarioLO)httpServletRequest.getSession().getAttribute("usuario"); 
    initBusiness(); 
    oiu = new OrdenIngresoUtil(); 
    oiu.setVista("LISTA"); 
    oiVista = new OrdenIngresoDTO(); 
    pathBodyOrdenIngreso = "/pages/logistica/movimientos/orden_ingreso/lista_orden_ingreso.xhtml"; 
} 

private void initBusiness() { 
    ServletContext servletContext = (ServletContext)facesContext.getExternalContext().getContext(); 
    ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); 
    ordenIngresoBO = (OrdenIngresoBO)ctx.getBean(strBusiness); 
} 

... 

public void actualizarVista() { 
    if(oiu.getIdEmisorComprobante().intValue() < 0){ 
     ProveedorBean proveedorBean = new ProveedorBean(); 
     proveedorBean.limpiarProveedorVista(); 
     proveedorBean.setPathBodyProveedor("/pages/logistica/proveedor/crear_proveedor.xhtml"); 
     RequestContext.getCurrentInstance().update(":idCentroPagina"); 
    } 
} 
在“actualizarVista”我想换到其他视图,以 /pages/logistica/proveedor/crear_proveedor.xhtml是另一个bean的,但要做到这一点我必须更新组件“idCentroPagina”这是

principal.xhtml。我与RequestContext.getCurrentInstance().update(":idCentroPagina")一起工作,但不起作用。

回答

1

删除前导冒号。前导冒号只有在命名容器内时才可用。因此,改变

RequestContext.getCurrentInstance().update(":idCentroPagina") 

RequestContext.getCurrentInstance().update("idCentroPagina") 
相关问题