hai我需要你的帮助..我有一个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>
保存按钮应该在控制器中调用保存用户..但它没有调用
答案 0 :(得分:1)
每当你尝试使用JSF的commandButton或任何构建它的Framework时,你都不应该忘记<h:form>
其中任何commandButton应该在其中,检查你的commandButton是否在<h:form>
:< / p>
<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>