1

I am opening a modal which has form in it. I am trying to check if the button is clicked or not by #{empty param['buttonid']}. But it is always shows empty even when clicked.

<div class="modal fade" jsf:id="dataReset">
        <div class="modal-dialog">
             <form jsf:id="reset-data-form" class="form-horizontal">
                <div class="modal-content">
                    <div class="modal-header">                  
                        <h4 class="modal-title">Modal Header</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-3 control-label">Email</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" 
                                       jsf:id="inputEmail" jsf:value="#{dataResetFacade.dataResetEmail}"                          
                                       name="inputEmail" />
                                <h:message for="inputEmail" p:class="error-msg"/>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default"
                            data-dismiss="modal">#{msg['general.button.cancel']}</button>
                        <button class="btn btn-primary" jsf:id="reset-data-button" 
                            jsf:action="#{dataResetFacade.resetdata}">submit
                            <f:ajax execute="@form" render="@form aaa bbb messages" onevent="close"/>
                        </button>
                         <h:outputText id="aaa" value="#{not empty param['reset-data-button']}"/>
                         <h:outputText id="bbb" value="#{empty param['reset-data-button']}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>

Am I doing some thing wrong.

Patan
  • 17,073
  • 36
  • 124
  • 198

1 Answers1

3

You did not specify the right request parameter name there. The request parameter name is basically the JSF component's client ID. The client ID of a JSF input and button component is represented by the HTML element's name attribute. You can find it out by just looking at the JSF-generated HTML output via rightclick, View Source in webbrowser.

Given the current view, that'll look like as below:

<button name="reset-data-form:reset-data-button" ... />

Alter parameter names accordingly:

<h:outputText id="aaa" value="#{not empty param['reset-data-form:reset-data-button']}" />
<h:outputText id="bbb" value="#{empty param['reset-data-form:reset-data-button']}" />

Alternatively, just bind the JSF UIComponent instance to an unique variable name in Facelet scope using binding attribute and then let JSF evaluate the UIComponent#getClientId().

<button jsf:binding="#{resetButton}" ... />
...
<h:outputText id="aaa" value="#{not empty param[resetButton.clientId]}" />
<h:outputText id="bbb" value="#{empty param[resetButton.clientId]}" />

Note: do not bind it to a bean property. The above code is as-is.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555