简体   繁体   中英

JSF Deselect selectOneRadio

Is it possible to deselect/uncheck items is <p:selectOneRadio> or <h:selectOneRadio/> ?

<h:selectOneRadio value="#{adminManageBroadcastController.selectedImage}" converter="#{broadcastImageConverter}">
    <f:selectItems value="#{adminManageBroadcastController.fileUploadList}"  var="image"
        itemValue="#{image}"
        itemLabelEscaped="false"
        itemLabel="&lt;img src=&quot;#{facesContext.externalContext.requestContextPath}#{image.url}&quot; width=&quot;20&quot; height=&quot;20&quot; alt=&quot;broadcast_img&quot;&gt;"
     />
</h:selectOneRadio>

If I understood your problem right, I think the following should help you. As you would like to deselect the radio-button when it is clicked again you should - as you already said - use an ajax listener which is called on click of the radio button. But first of all you have to save the value of the radio button on each change, so you have to add another eventlistener which submits the value of the radio button on change . When the selected button is now clicked again you can check which button is clicked and then check in your bean if this button is the selected button (if it has the value which is set on the bean). If the button is the selected button you set the referenced value on the bean to null and update the selectOneRadio . I do not exactly know whats the structure of your application, so I will try to sketch what I mean in code:

<h:selectOneRadio value="#{adminManageBroadcastController.selectedImage}" converter="#{broadcastImageConverter}">
    <f:selectItems value="#{adminManageBroadcastController.fileUploadList}"  var="image"
           itemValue="#{image}"
           itemLabelEscaped="false"
           itemLabel="&lt;img src=&quot;#{facesContext.externalContext.requestContextPath}#{image.url}&quot; width=&quot;20&quot; height=&quot;20&quot; alt=&quot;broadcast_img&quot;&gt;"
     />
    <p:ajax event="change" process="@parent" partialSubmit="true"/>
    <p:ajax event="click" process="@this" listener="#{adminManageBroadcastController.deselectImage()}" update="@parent"/>
</h:selectOneRadio>

Another option would be to do the whole thing using JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM