【问题标题】:JSF with bootstrap.command button is not invoking the controller带有 bootstrap.command 按钮的 JSF 未调用控制器
【发布时间】:2014-08-08 21:39:58
【问题描述】:

大家好,我需要你们的帮助..我有一个 jsf 表单..但是命令按钮没有调用控制器.. 这是我的jsf代码

<h:form class="form-horizontal" method="post" action="#{user.saveUser}" enctype="multipart/form-data">
    <div class="col-lg-12">
        <div class="panel panel-default top-margin">
            <div class="panel-body page-title">User Management</div>
        </div>
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-body panel-pad">
                <div style="padding:7px 0 0 0;" class="col-lg-12 col-md-12 col-sm-12">
                    <div class="form-group">
                        <label class="control-label col-md-2"> First Name <span class="red">*</span> </label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.firstName}" required="true" class="form-control"/> </div>
                        <label class="control-label col-md-2"> Middle Name <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.middleName}" required="true" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Last Name <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.lastName}" required="true" class="form-control"/> </div>
                        <label class="control-label col-md-2">Citizen Service No. <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.citizenServiceNo}" required="true" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Gender <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:selectOneMenu value="#{user.gender}" class="form-control">
                                <f:selectItem itemValue="select" itemLabel="select"></f:selectItem>
                                <f:selectItem itemValue="m" itemLabel="male" ></f:selectItem>
                                <f:selectItem itemValue="f" itemLabel="female"></f:selectItem>
                            </h:selectOneMenu>
                        </div>
                        <label class="control-label col-md-2"> Date of Birth <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.dob}" required="true" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Address 1 <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.address1}" class="form-control"/> </div>
                        <label class="control-label col-md-2"> Country <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:selectOneMenu value="#{user.countryName}" class="form-control">
                                <f:selectItem itemLabel="select"/>
                                <f:selectItems value="#{user.countries}" var="country" itemValue="#{country.countrySeqId}" itemLabel="#{country.countryName}"></f:selectItems>
                            </h:selectOneMenu>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Address 2 </label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.address2}" class="form-control"/> </div>
                        <label class="control-label col-md-2"> Street <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.street}" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Postal Code <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.pinCode}" class="form-control"/> </div>
                        <label class="control-label col-md-2"> City <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.city}" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">Maritial Status <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:selectOneMenu value="#{user.maritalStatus}" class="form-control">
                                <f:selectItem itemValue="select" itemLabel="select"></f:selectItem>
                                <f:selectItem itemValue="married" itemLabel="married"></f:selectItem>
                                <f:selectItem itemValue="unmarried" itemLabel="unmarried"></f:selectItem>
                            </h:selectOneMenu>
                        </div>
                        <label class="control-label col-md-2"> Nationality <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.nationality}" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Tele Phone </label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.mobileNumber}" class="form-control"/> </div>
                        <label class="control-label col-md-2"> Mobile </label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.mobileNumber}" class="form-control"/> </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> Email <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.emailId}" class="form-control"/> </div>
                        <label class="control-label col-md-2"> Company Name <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:selectOneMenu value="#{user.companyName}" class="form-control">
                                <f:selectItem itemLabel="select"/>
                                <f:selectItems value="#{user.companies}" var="company" itemValue="#{company.companySeqId}" itemLabel="#{company.companyName}"/>
                            </h:selectOneMenu>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2"> User ID <span class="red">*</span></label>
                        <div class="col-md-4">
                            <h:inputText value="#{user.userId}" class="form-control"/> </div>
                    </div>
                    <div class="form-group" style="margin:10px 0 20px 0;">
                        <label class="control-label col-md-2 col-sm-1 col-xs-2"> User </label>
                        <div class="col-md-1 col-sm-2 col-xs-3"> <img src="../img/avatar3.png" class="avatar-w img-responsive" /> </div>
                        <div class="browse-margin col-xs-">
                            <h:inputFile  id="exampleInputFile"/> </div>
                    </div>
                </div>
                <div class="clearfix"> </div>        
                <!-- roles allocation starts --> 
                <div class="page-title"> Roles Allocation </div>
                <div class="col-md-5 col-xs-5">
                    <div class="panel panel-default">
                        <div class="panel-heading">All Roles</div>
                        <div class="panel-body">
                            <div class="permn-box">
                                <h:selectManyListbox  multiple="multiple">
                                    <f:selectItems value="#{user.roles}" var ="role" itemValue="#{role.roleSeqId}" itemLabel="#{role.roleName}"/>
                                </h:selectManyListbox>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-2 col-xs-2">
                    <div class="text-center arrows-pt">
                        <div class="btn-group-vertical">
                            <h:commandButton  type="button" class="btn btn-default"><i class="fa fa-angle-right fa-lg"></i> </h:commandButton>
                            <h:commandButton type="button" class="btn btn-default"><i class="fa fa-angle-double-right fa-lg"></i></h:commandButton>
                            <h:commandButton type="button" class="btn btn-default"><i class="fa fa-angle-double-left fa-lg"></i></h:commandButton>
                            <h:commandButton type="button" class="btn btn-default"><i class="fa fa-angle-left fa-lg"></i> </h:commandButton>
                        </div>
                    </div>
                </div>
                <div class="col-md-5 col-xs-5">
                    <div class="panel panel-default">
                        <div class="panel-heading">Selected Roles</div>
                        <div class="panel-body">
                            <div class="permn-box">
                                <h:selectManyListbox multiple="multiple">
                                    <f:selectItems value="#{user.roles}" var ="role" itemValue="#{role.roleSeqId}" itemLabel="#{role.roleName}"/>
                                </h:selectManyListbox>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-12">
                        <div class="pull-right">
                            <h:commandButton action="#{user.saveUser}"  class="btn btn-primary " type="button" data-original-title="" title="">Save</h:commandButton>
                            <h:commandButton class="btn btn-primary " type="button" data-original-title="" title="">Reset</h:commandButton>
                            <h:commandButton class="btn btn-primary " onclick="window.location = 'user-management.html';" type="button" data-original-title="" title="">Cancel</h:commandButton>
                        </div>
                    </div>
                </div>
                <!-- ./ roles allocation starts -->     
            </div>
        </div>
    </div>
</h:form>

保存按钮应该调用控制器中的保存用户..但它没有调用

【问题讨论】:

标签: java spring twitter-bootstrap rest jsf


【解决方案1】:

当您尝试使用 JSF 的 commandButton 或任何基于其构建的框架时,您不应该忘记 &lt;h:form&gt; 任何 commandButton 应该在其中,检查您的 commandButton 是否在 &lt;h:form&gt; 内:

<h:form>
<!-- Here you put all field/input that you want to send in your request -->

   <h:commandButton action="#{user.saveUser}"  type="button" class="btn btn-primary" data-original-title="" title="">Save </h:commandButton>
<!-- you can add more button here with differents action method -->
</h:form>

【讨论】:

  • hai mifmif...感谢回复我在
    中有命令按钮..但它仍然无法正常工作
  • 检查请求是否发送到服务器(在您的浏览器中尝试检查网络通信)
猜你喜欢
  • 1970-01-01
  • 2015-01-24
  • 1970-01-01
  • 1970-01-01
  • 2018-11-26
  • 1970-01-01
  • 2018-08-15
  • 2019-01-28
  • 2018-05-24
相关资源
最近更新 更多