English 中文(简体)
命令按钮 ajax 调用时没有反映所选按按按键所选的值
原标题:Radio button selected value is not getting reflected in command button ajax call
  • 时间:2012-05-22 06:41:29
  •  标签:
  • jsf-2

我对无线电按钮有问题 。 我有一个 2 个无线电按钮和一个命令按钮。 根据选择的无线电按钮, 尊重的值将通过 ajax 调用显示 。 但问题总是第一个按钮在命令按钮动作中被调用, 这就是为什么第一个值总是被显示, 不管选择第二个 。 这是我的代码。

///测试.xhtml

    <h:panelGroup id="demandDashBoardPanelGroupID">
    <fieldset> 
    <legend style="font-family:Arial;font-size: 12px;">Demand Dashboard</legend>

     <table>
        <tr>
        <td> 
            <h:selectOneRadio immediate="true" id="groupbyid" value="#{demandManagedBean.selectedRadioButton}" styleClass="labelstyle">  
                    <f:selectItem itemLabel="Group By Creation Date Time" itemValue="1" />  
                    <f:selectItem itemLabel="Group By Location" itemValue="2" />
            </h:selectOneRadio>
        </td>
        <td>

            <h:commandButton id="fetchbuttonID" value="Fetch" 
                    style="font-size:13px;width:60px;height:25px;" action="#{demandManagedBean.displayDemandRequestsTable}">
                    <f:setPropertyActionListener target="#{demandManagedBean.selectedRadioButtonParam}" value="#{demandManagedBean.selectedRadioButton}"/>
                    <f:ajax render=":parentformid:demandrequestpanelgrpid" immediate="true"/> 
            </h:commandButton>
        </td>
        </tr>
        </table>

     </fieldset>

     </h:panelGroup>

    <h:panelGroup id="demandrequestpanelgrpid" rendered="#{demandManagedBean.renderedFieldSet}"> 

     <fieldset id="demandrequestfieldsetid"> 

     <legend style="font-family:Arial;font-size: 12px;">Demand Requests</legend>

            <h:outputText rendered="#{demandManagedBean.renderCreationdateDmdtable}" value="first table"/>

            <h:outputText rendered="#{demandManagedBean.renderDmdLocationTable}" value="second table"/>

     </fieldset> 

   </h:panelGroup>

/ 支持豆的动作

public void displayDemandRequestsTable(){


        if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("1")){

            renderCreationdateDmdtable = true;
            renderDmdLocationTable = false;

        }else if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("2")){

            renderCreationdateDmdtable = false;
            renderDmdLocationTable = true;

        }
        renderedFieldSet = true;
    }
问题回答

您不需要 f: setPropertyActionListener 在此将选中的值移入您的背豆。 只要在您的 f:ajax 标签上添加一个 execut 属性, 并删除 imimimmete= true :

<h:commandButton ...>
   <f:ajax render=":parentformid:demandrequestpanelgrpid" execute="@form" /> 
</h:commandButton>

您也可以只给出要执行的部件的代号, 而不是整个表单 :

<h:commandButton ...>
   <f:ajax render=":parentformid:demandrequestpanelgrpid" execute="groupbyid" /> 
</h:commandButton>

还要确保您所支持的豆子正确初始化了 所选择的中继按钮 < / code >,并且该豆至少在_ViewScoped 中。

UPDATE: If you remove the f:setPropertyActionListener then the selectedRadioButtonParam will not be set. Then you need to check selectedRadioButton inside your action method instead.





相关问题
JSF redirect doesn t work

I have a problem with redirecting a page in my JSF application. My navigation rule look like this : <navigation-rule> <from-view-id>/index.xhtml</from-view-id> <...

Get JSF managed bean by name in any Servlet related class

I m trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I m hoping to map: http://host/app/myBean/myProperty to: @ManagedBean(name="myBean"...

JSF2 - what scope for f:ajax elements?

I have this form: <h:form> <h:outputText value="Tag:" /> <h:inputText value="#{entryRecorder.tag}"> <f:ajax render="category" /> </h:inputText> ...

Modifying JSF Component Tree in PhaseListener

I m having an issue. I ve implemented a PhaseListener, which is meant to add a style class to any UIInput components in the tree that have messages attached to them, and removes the style class if it ...

JSF 2 - clearing component attributes on page load?

The real question: Is there a way to clear certain attributes for all components on an initial page load? Background info: In my application, I have a JSF 2.0 frontend layer that speaks to a service ...

JSF2 - backed by EJB or ManagedBean?

As I am learning JSF2, I realized I am not sure what the backing components should be. From design point of view, what is the difference between EJBs and @ManagedBeans? In the end I am going to use ...