JSF访问Bean类中的html元素值 [英] JSF access html element value in bean class

查看:110
本文介绍了JSF访问Bean类中的html元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF应用程序,其中有一个组合框.

I have a JSF application in which I have a combo box.

<h:selectOneMenu id="collectorType"
                           value="#{activityDataSource.object.type}"
                           rendered="#{empty activityDataSource.object.id}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           onchange="$('editForm:selectTypeButton').click();">
             <f:ajax event="change" 
                    execute="@this" 
                    render="dsTransformationRule dsCorrelationRule"
                    listener="#{activityDataSource.handleCollectorTypeChange}" />
            <f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
            <f:selectItems value="#{activityDataSource.collectorTypes}"/>
          </h:selectOneMenu>

我正在像下面这样的Bean类中获得该组合框的选定值:

And I am getting selected value of that combo box in bean class like:

public void setSelectedTransformationRule(String transformationRule)
        throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

我成功地做到了.我通过combobox的ajax onchage事件调用此方法.

And I am successful in doing so. I am calling this method through ajax onchage event of combobox.

但是,如果我尝试通过其他方法获得相同的组合框值,则会得到空值.

But if I try to get same combo box value in a different method i get null value.

public void handleCollectorTypeChange() throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

任何帮助!

推荐答案

请尝试将属性process和partialSubmit放入您的ajax调用中,并使用所需的值,如下所示:

try put the attributes process and partialSubmit in your ajax call with the values you need process like this:

<f:ajax event="change" 
   execute="@this" 
   render="dsTransformationRule dsCorrelationRule"
   process="@this, collectorType"
   partialSubmit="true"
   listener="#{activityDataSource.handleCollectorTypeChange}" />

在处理过程中,您可以将需要处理的所有ID放入更新后的值中(就像您在屏幕上看到的一样.

In the process atrribute you can put all ids you need to process with the updated values (like you see in the screen.

这篇关于JSF访问Bean类中的html元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆