JSF2 web应用程序中可能存在的范围问题

JSF2 web应用程序中可能存在的范围问题,jsf,jsf-2,spring-3,mojarra,Jsf,Jsf 2,Spring 3,Mojarra,我有一个使用SPRING3+JSF2(mojarra 2.1.12)的JSF web应用程序,我认为有一些问题可能是由于在JSF2+primefaces接口的一个组合中对一个控制器的作用域选择不当造成的 这个组合功能允许用户选择一个内部xhtml子页面和一个自动重定向到该页面的按钮 该网站使用了一种模板技术:有一个带有JSF2代码的模板(standard.xhtml),使用这个模板有几个页面:一个是主页的inicio.xhtml,一个是联系人页面(contacto.xhtml)。在这两个页面中,

我有一个使用SPRING3+JSF2(mojarra 2.1.12)的JSF web应用程序,我认为有一些问题可能是由于在JSF2+primefaces接口的一个组合中对一个控制器的作用域选择不当造成的

这个组合功能允许用户选择一个内部xhtml子页面和一个自动重定向到该页面的按钮

该网站使用了一种模板技术:有一个带有JSF2代码的模板(standard.xhtml),使用这个模板有几个页面:一个是主页的inicio.xhtml,一个是联系人页面(contacto.xhtml)。在这两个页面中,组合正确显示

下面的代码表明,只有当您在主页(incio.xhtml)上导航时,它才能正常工作,但当您在web的其他部分(即contacto.xhtml)时,它会显示包含所有选项的组合,但按钮根本不起作用

这是我在standard.xhtml文件中的代码:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
       xml:lang="${userContext.locale}" lang="${userContext.locale}"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:c="http://java.sun.com/jsp/jstl/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:p="http://primefaces.org/ui"
       xmlns:sec="http://www.springframework.org/security/tags">
<f:view contentType="text/html">
       <h:head>
             //HEAD
       </h:head>
       <body>
             <div id="…">
                    <div id="…">

                           //CODE
                           //CODE to go from one page (inicio.xhtml) to other (contacto.xhtml)
                                  <li><h:commandLink value="${msg.app_menu_contacto}" action="mContacto" /></li>

                           //MORE CODE
                           <h:form>
                                  //MORE CODE
                                  <h:panelGrid id="buscar" columns="2" style="margin-top:20px;" cellpadding="5">
                                  <p:selectOneMenu id="selectBuscar" value="#{buscador.procedimiento}" panelStyle="width:150px;"  
                                         var="p" style="width:220px; margin-right: 10px; "  filter="true" filterMatchMode="startsWith">  
                                        <f:selectItem itemLabel="${msg.app_comun_seleccionar}" itemValue="" />  
                                        <f:selectItems value="#{buscador.procedimientos}" var="proc" itemLabel="#{proc.codigo}" itemValue="#{proc.valor}"/>
                                        </p:selectOneMenu>
                                              <p:commandButton id="btnIr" style="width:40px" value="#{msg.app_comun_btn_ir}" title="#{msg.app_comun_btn_ir_title}" 
                                                action="#{buscador.direccion}">
                                        </p:commandButton> 
                                  </h:panelGrid>
                                  </h:form>
                           </div>
                    </div>
       </body>
</f:view>
</html>

//头
//代码
//从一个页面(inicio.xhtml)转到另一个页面(contacto.xhtml)的代码
  • //更多代码 //更多代码
    在faces-navigation.xml中,我们有以下几行代码(faces-navigation仅用于代码的几个继承部分):

    
    麦康塔克托
    /views/comun/contacto.xhtml
    
    工作所在的xhtml主页的代码:

    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:fn="http://java.sun.com/jsp/jstl/functions"
           xmlns:c="http://java.sun.com/jsp/jstl/core"
           xmlns:p="http://primefaces.org/ui"
        xmlns:sec="http://www.springframework.org/security/tags"
           template="/WEB-INF/layouts/standard.xhtml">
    
    //Code independent of the combo or button failing
    // it uses ui:define to show different components in the page.
    
        </ui:composition>
    
    
    //代码独立于组合或按钮失败
    //它使用ui:define在页面中显示不同的组件。
    
    这是控制器代码:

    @Controller("buscador")
    //@Scope(“Session”)  Do not work with “request”, “view” or without scope
    public class BuscadorController implements Serializable {
    
           public List<ValorCombo> getProcedimientos() {
                 //Code that returns a list of pair String to show in the combo, name of the xhtml page should be redirected
    }
    
    public String direccion() {
    //CODE
    String salida = "proc/"+procedimiento+"?faces-redirect=true";
    //more CODE
    return salida;
    }
    
    @控制器(“总线控制器”)
    //@范围(“会议”) 不要使用“请求”、“视图”或无范围
    公共类BuscadorController实现可序列化{
    公共列表getProcedimientos(){
    //返回要在组合中显示的对字符串列表的代码,应重定向xhtml页面的名称
    }
    公共字符串目录(){
    //代码
    字符串salida=“proc/”+procediemento+“?faces redirect=true”;
    //更多代码
    返回萨利达;
    }
    
    }

    我试过这个,但也不管用

    我怎样才能解决这个问题


    谢谢

    是否命中
    direccion()
    方法?是。输出类似于:proc/functionName?var=0&;faces redirect=True这是目标视图的导航结果。在使用JSF2时,使用导航案例(xml文件)毫无意义,除非您想使用条件导航。对于您的情况,您可以转到
    contacto.xhtml
    返回
    mContacto
    direccion()
    方法中的查看路径
    /views/comun/contacto
    。但是,在本例中,您返回的是
    proc/functionName
    ,它是否与您的任何路径匹配?是的,使用组合键,用户选择functionName(这是他想要进入的网页),按下按钮时,它将进入。此重定向在inicio.xhtml中工作,但在从contacto.xhtml页面调用时,它的工作代码不同(因为它在模板中)。因此,我认为这是一个bean范围的问题,或者与我如何从incio.xhtml转到contacto.xhtml有关的问题,但是我找不到错误,可能只是路径问题。您正在指定一个相对路径,它适用于
    inicio
    位置,但不适用于另一个位置。切换到绝对值
    /proc/functionName
    @Controller("buscador")
    //@Scope(“Session”)  Do not work with “request”, “view” or without scope
    public class BuscadorController implements Serializable {
    
           public List<ValorCombo> getProcedimientos() {
                 //Code that returns a list of pair String to show in the combo, name of the xhtml page should be redirected
    }
    
    public String direccion() {
    //CODE
    String salida = "proc/"+procedimiento+"?faces-redirect=true";
    //more CODE
    return salida;
    }