【问题标题】:FacesComponent works in one page but doesn't in others (retrieves null from ajax event)FacesComponent 在一个页面中有效,但在其他页面中无效(从 ajax 事件中检索 null)
【发布时间】:2018-02-27 03:45:59
【问题描述】:

我不知道是否有一个已解决的问题。如果是这样,我找不到它。

我正在创建一个包含两个触发事件的 SelectOneMenu 的复合组件。 问题是这个组件在一个 jsf 中工作,但在其他 jsf 中不工作。

组件位于三个不同的 xhtml 中。在所有这些事件中,当我更改第一个 SelectOneMenu 的值时会触发该事件,但仅在其中一个 xhtml 中,SelectItem 的值不为空。在其余部分中,检索到的值为“null”

 //In p001DatosNotificacion.xhtml, it retrieves the selected value of the selectonemenu (b, for example)
 //In the others it retrieves null

 UISelectOne oneVoewl = (UISelectOne)event.getSource();
 System.out.println("One Voewl > " + oneVoewl.getValue());

谁能帮助我并告诉我哪里出错了?

提前致谢!

代码

组件支持 bean

@FacesComponent(value="letterExample")
public class LetterExample extends UINamingContainer{

    public void voewlAjaxListener(AjaxBehaviorEvent event){
        UISelectOne oneVoewl = (UISelectOne)event.getSource();
        System.out.println("One Voewl > " + oneVoewl.getValue());

    }

复合组件注意:我正在使用现有的 bean 进行测试

<cc:interface componentType="letterExample" >
    <cc:attribute name="bean" type="es.ccasa.sgnx.business.bean.Direccion" />
</cc:interface>


<cc:implementation>

    <p:selectOneMenu id="oneMenuVoewl" value="#{cc.attrs.bean.codigoPais}" 
        binding="#{cc.uiSelectOneVoewl}" >
            <f:selectItem itemLabel="Aaaa" itemValue="a" />
            <f:selectItem itemLabel="Eeee" itemValue="e" />
            <f:selectItem itemLabel="Iiii" itemValue="i" />
            <f:selectItem itemLabel="Oooo" itemValue="o" />
            <f:selectItem itemLabel="Uuuu" itemValue="u" />
        <p:ajax event="change"  listener="#{cc.voewlAjaxListener}" update="consonantWrapper" />
    </p:selectOneMenu>

    <h:panelGroup id="consonantWrapper" layout="block">
        <p:selectOneMenu id="oneMenuConsonant"  value="#{cc.attrs.bean.codigoProvincia}"
            binding="#{cc.uiSelectOneConsonant}">
                <f:selectItem itemLabel="Bbbb" itemValue="b" />
                <f:selectItem itemLabel="Cccc" itemValue="c" />
                <f:selectItem itemLabel="Dddd" itemValue="d" />
        </p:selectOneMenu>

    </h:panelGroup>

</cc:implementation>

豆子

public class Direccion implements Serializable {
    private String codigoPais; /* with its getter and setter*/
    private String codigoProvincia; /* with its getter and setter*/

}

XHTML 这是我在 xhtml 页面中使用的方式:(控制器名称的变化取决于当前控制器)

<sgnx:letter-example bean="#{controller.direccion}" />

@Named bean

@Named
@ViewScoped
public class P001DatosNotificacionController
    private Direccion direccion; /* with its getter and setter*/

@Named
@ViewScoped
public class P001GestionNotificacionesController
    private Direccion direccion; /* with its getter and setter*/

@Named
@ViewScoped
public class P002BandejaProvisionalNotificacionesController
    private Direccion direccion; /* with its getter and setter*/

【问题讨论】:

    标签: jsf composite-component


    【解决方案1】:

    几周后,我又回到了这个问题上。 我决定从头开始。

    当我开始编写控制器代码并使用 @ViewScoped 对其进行注释时,我意识到 javax.faces.beanjavax.faces.view

    这就是错误。我使用了错误的组合:

    import javax.inject.Named;    
    import javax.faces.bean.ViewScoped;
    

    因此,解决方案就像使用适当的包组合一样简单:

    import javax.inject.Named;
    import javax.faces.view.ViewScoped;
    

    在这些帖子中有答案和解释:

    1. @ViewScoped bean recreated on every postback request when using JSF 2.2
    2. ManagedProperty in CDI @Named bean returns null
    3. Inject CDI bean into JSF @ViewScoped bean

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 2012-08-09
      相关资源
      最近更新 更多