I want to get #Transient values from HTML.I had tried #Basic,it creates entry in db. I need to get this value.
Pojo:
#Transient
private int dueAmount;
public int getDueAmount() {
return dueAmount = this.getPaymentTotal() - this.getBillAmount() - this.getDiscountTotal();
}
public void setDueAmount(int dueAmount) {
this.dueAmount = dueAmount;
}
Controller
#RequestMapping(value="/billByPatientId/{id}", method = RequestMethod.GET)
public List<Bill> getBillsByPatientId(#PathVariable("id") String patientId)throws Exception {
List<Bill> BillDetailsByPatientId = billService.getBillsByPatientId(patientId);
for(Bill b : BillDetailsByPatientId){
System.out.println(b.getDueAmount());
}
return billService.getBillsByPatientId(patientId);
}
Js
$http.get('/bill/billByPatientId/'+patientData.id)
.success(function (data, status, headers, config) {
console.log(data)
$scope.bills = data;
});
HTML
<table data-ng-show='bills.length > 0' class="table table-hover">
<thead>
<tr>
<th class="col-lg-1 text-center">Bill No</th>
<th class="col-lg-3 text-center">Status</th>
</tr>
</thead>
<tr data-ng-repeat="bill in bills">
<td class="text-center">{{bill.billNo}}</td>
<td class="text-right">{{bill.dueAmount}}</td>
</tr>
In my current code i get " dueAmount " value because of printing " dueAmount " in my Controller, otherwise values will be null.
How to do this ?
I Referrer this document
Related
I cant solve this problem, i need some help
this is the .html code
<tr data-th-each="user : ${Users}">
<td data-th-text="${Users.user_id}"></td>
<td data-th-text="${Users.user_name}"></td>
<td data-th-text="${Users.user_email}"></td>
<td data-th-text="${Users.user_telephone}"></td>
<td data-th-text="${Users.user_type}"></td>
<td data-th-text="${Users.user_available}"></td>
</tr>
</tbody>
</table>
</section>
<br>
<a class="btn btn-info" href="/newUser">Crear Usuario</a>
<a class="btn btn-info" href="/">Volver</a>
</body>
</html>
and this is the .java of user
public Users() {
super();
}
public Users(String user_id, String user_name, String user_email, String user_password, int user_telephone, String user_type, int user_available) {
this.user_id = user_id;
this.user_name = user_name;
this.user_email = user_email;
this.user_password = user_password;
this.user_telephone = user_telephone;
this.user_type = user_type;
this.user_available = user_available;
}
//Getters
public String getUserId() {
return user_id;
}
public String getUserName() {
return user_name;
}
public String getUserEmail() {
return user_email;
}
public String getUserPassword() {
return user_password;
}
public int getUserTelephone() {
return user_telephone;
}
public String getUserType() {
return user_type;
}
public int getUserAvailable() {
return user_available;
}
}
ok this is all the code of user.java
what should i do to solve this error
its for a sprint project
but why i cant send this, lol
Hi please check this example
<table>
<th:block th:each="user : ${users}">
<tr>
<td th:text="${user.login}"></td>
<td th:text="${user.name}"></td>
</tr>
</th:block>
</table>
enter image description hereI have the following list which is coming from a class via toString method .
I am passing the list in modelAndView object to jsp page.
Now I want to loop over the list and make a table in jsp Page.
Please guide.
List<LocationStats> allStates = [LocationStats{state='Fujian', country='Afghanistan', latestTotalCases=51526}, LocationStats{state='Guangdong', country='Albania', latestTotalCases=59438}] ;
////////////////////////// LocationStats.JAVA ///////////////////////////////////////
public class LocationStats {
private String state;
private String country;
private int latestTotalCases;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLatestTotalCases() {
return latestTotalCases;
}
public void setLatestTotalCases(int latestTotalCases) {
this.latestTotalCases = latestTotalCases;
}
#Override
public String toString() {
return "LocationStats{" +
"state='" + state + '\'' +
", country='" + country + '\'' +
", latestTotalCases=" + latestTotalCases +
'}';
}
}
///////////////////////////// HomeController.java ////////////////////////
#RequestMapping("/")
public ModelAndView home() {
ModelAndView mv = new ModelAndView();
mv.addObject("location", coronaVirusDataService.getAllStates());
mv.setViewName("home.jsp");
return (mv);
}
/////////////////// home.jsp //////////////////////
<table>
<tr>
<th>state</th>
<th>country</th>
<th>latestTotalCases</th>
</tr>
<tr th:each="elements : ${location}">
<td th:text="${elements.state}"></td>
<td th:text="${elements.country}"></td>
<td th:text="${elements.latestTotalCases}">0</td>
</tr>
</table>
You should add taglib at the beginning of jsp file.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Than you can write it in this way:
<table>
<tr>
<th>state</th>
<th>country</th>
<th>latestTotalCases</th>
</tr>
<c:forEach items="${location}" var="elements">
<tr>
<td>${elements.state}</td>
<td>${elements.country}</td>
<td>${elements.latestTotalCases}</td>
</tr>
</c:forEach>
</table>
You can also check if this 'location' is not empty, for example by printing it out:
<%=location%>
<table>
<tr>
<th>state</th>
<th>country</th>
<th>latestTotalCases</th>
</tr>
<c:forEach items="${location}" var="element">
<tr>
<td>${element.state}</td>
<td>${element.country}</td>
<td>${element.latestTotalCases}</td>
</tr>
</c:forEach>
</table>
I have limit query on the server side which returns me data between startResult and maxResult. I want to reload data table when length of page changes.
This is my Html code:
<table class="table table-striped" id = "cardTable">
<thead>
<tr>
<th>expression</th>
<th>type</th>
<th>edit card</th>
</tr>
</thead>
<tbody>
<c:forEach var="card" items="${cards}">
<tr>
<td>${card.expression}</td>
<td>${card.type.name} <input class="card" name="card" type="hidden" value="${card.id }"></td>
<!--<td><button data-toggle="modal" data-target="#cardUpdate" class="btn btn-primary">Edit</Button></td>-->
<td><button class="updateCard btn-primary">edit</button></td>
</tr>
</c:forEach>
</tbody>
This is my controller:
#RequestMapping(value="/card.html/{startResult}/{maxResult}", method=RequestMethod.GET)
private #ResponseBody ModelAndView getCardPage(#PathVariable("startResult") int start,#PathVariable("maxResult") int maxResult) {
cards = (ArrayList<Card>) cardDao.findWithLimit(start,maxResult);
ModelAndView cardView = new ModelAndView("Card");
cardView.addObject("cards",cards);
cardView.addObject("types",types);
return cardView;
}
This is my ajax code:
function resetTable(startResult,maxResult) {
$.ajax({
type:"GET",
url: contexPath + "/card.html/" + startResult + "/" + maxResult,
data: "startResult=" + startResult + "&maxResult=" + maxResult,
success:function() {
alert("success")
},
error:function(e) {
alert('fail')
}
});
}
I have tried this
$('#cardTable').on( 'length.dt', function ( e, settings, len ) {
$("#cardTable").DataTable().clear().draw();
resetTable(0,10);
} );
})
But it has not worked. Can anyone help me please?
1st problem : i have a jsp in which there are two tabs ,for the second tab i have included the struts include tag. When i open the second tab and performs the action the second tab form values are not passing to the action.
2nd problem : in the select tag i have populate the list but it is coming as prepopulated means all the options are coming as selected="selected"
main jsp in which tabs are made
<!-- admin first tab starts here -->
<form action="saveRolesAndPermissions" method="post">
<table align="center">
<tr>
<td ><s:text name="FTID" ></s:text></td>
<td ><s:textfield id="FTID" name="ft_id">
</s:textfield></td>
<td><input type="button" value="validate" onclick="userPresent()"></td>
</tr>
</table>
<table>
<tr>
<td>First Name</td>
<td><input id="first_name" type="text" readonly onkeydown="return false"></td>
<td>Last Name</td>
<td><input id="last_name"
type="text" readonly onkeydown="return false"></td>
<td>Email-Id</td>
<td><input id="mail_id" type="text"
readonly onkeydown="return false"></td>
</tr>
</table>
<table align="center">
<tr>
<td><s:text name="ROLES"></s:text></td>
<td></td>
<td></td>
</tr>
<tr>
<td><s:text name="Available Roles"></s:text></td>
<td></td>
<td><s:text name="Assigned Roles"></s:text></td>
</tr>
<tr>
<td><s:select id="roles" name="availableRole"
multiple="true" list="availableRole"></s:select></td>
<td><input type="button" value=">" onclick="move_list_items('roles','assignedroles');"/><input
type="button" value="<" onclick="move_list_items('assignedroles','roles');"/></td>
<td><s:select id="assignedroles" name="assignedRole" multiple="true"
list="{}" >
</s:select></td>
</tr>
</table>
<br /> <br /> <br />
<table>
<tr>
<td><s:text name="Permissions"></s:text></td>
<td></td>
<td> </td>
</tr>
<tr>
<td><s:text
name="Available Permissions"></s:text></td>
<td></td>
<td><s:text name="Assigned Permissions"></s:text></td>
</tr>
<tr>
<td><s:select id="permissions" multiple="true"
name="availablePermission" list="availablePermission" headerValue=""></s:select></td>
<td><input
type="button" value=">" onclick="move_list_items('permissions','assignedpermissions');"/><br /> <input type="button"
value="<" onclick="move_list_items('assignedpermissions','permissions');" /></td>
<td><s:select id="assignedpermissions" multiple="true" name="assignedPermission"
list="{}" ></s:select></td>
</tr>
</table>
<br /> <br />
<table align="center" style="width: 25%;">
<tr>
<td><s:if test="hasActionMessages()">
<div class="welcome" style="list-style:none">
<s:actionmessage />
</div>
</s:if></td>
</tr>
</table>
<table>
<tr>
<td><s:submit
value="save"onclick="saveRole();return false;"></s:submit></td>
<td> <input type="button" name="close"
value="close" /></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
<!-- second tab for modify roles -->
<div id="content02" class="content" >
<s:include value="../asp/aspAdminModify.jsp"></s:include>
</div>
<!-- /second tab ends here -->
included jsp
<form action="grantedRolesAndPermissions" method="post">
<table>
<tr>
<td><s:text name="FTID" ></s:text></td>
<td><s:textfield id="modify_FTID" name="modifyftid">
</s:textfield></td>
<td><s:submit
value="search" onclick="search();return false;"></s:submit>
</td>
</tr>
</table>
Bean for the first tab
private String ft_id;
private ArrayList<String> availableRole;
private ArrayList<String> availablePermission;
private ArrayList<String> assignedRole;
private ArrayList<String> assignedPermission;
//getters and setters
Action for the first tab
public class ASPadmin extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminBean>{
/**
*
*/
private static final long serialVersionUID = 1L;
private AdminASPService aspService = new AdminASPService();
private HttpServletRequest request = ServletActionContext.getRequest();
private HttpServletResponse response = ServletActionContext.getResponse();
public CMTUser cmtuser;
private ASPAdminBean aspAdminBean = new ASPAdminBean();
//getters and setters
public String populateRolesAndPermissions() throws Exception
{
/*aspAdminBean=new ASPAdminBean();*/
aspAdminBean.setAvailableRole(aspService.getRolesList());
aspAdminBean.setAvailablePermission(aspService.getPermissionsList());
return SUCCESS;
}
public String saveRolesAndPermissions() throws Exception
{
User user = CMTUser.getUser(request);
String login = user.getUserId();
String[] temp = login.split("\\.");
String abcfinal = temp[0].substring(0, 1).toUpperCase()
+ temp[0].substring(1);
String deffinal = temp[1].substring(0, 1).toUpperCase()
+ temp[1].substring(1);
String name = abcfinal + " " + deffinal;
System.out.println("name ==============>" + name);
String id = aspService.saveRolesPermissions(aspAdminBean,name);
System.out.println("id=======>"+id);
if("Y".equals(id)){
addActionMessage("Record Inserted Successfully");
populateRolesAndPermissions();
return SUCCESS;
}
else{
return ERROR;
}
}
#Override
public String execute() throws Exception {
String url = request.getRequestURL().toString();
String[] actionArray = url.split("/");
String event = null;
String forward = SUCCESS;
for (int i = 0; i < actionArray.length; i++) {
event = actionArray[i];
}
System.err.println(event);
try {
if (event.equals("aspAdmin.action")) {
populateRolesAndPermissions();
}
}catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
#Override
public void setServletRequest(HttpServletRequest req) {
this.request = req;
}
#Override
public ASPAdminBean getModel() {
// TODO Auto-generated method stub
return aspAdminBean;
}
}
bean for second tab
public class ASPAdminModifyBean {
private String modifyftid;
private String aspmodifyassignedRole;
private String aspmodifyassignedPermission;
private String createddate;
private String createdby;
private String updateddate;
private String updatedby;
private String username;
private ArrayList<String> modifyavailableRole;
private ArrayList<String> modifyavailablePermission;
private ArrayList<String> modifyassignedRole;
private ArrayList<String> modifyassignedPermission;
//getters and setters
action for the second tab
public class ASPadminModify extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminModifyBean> {
private AdminASPService aspService = new AdminASPService();
private GetRolePermissionListInt[] roleVO;
private HttpServletRequest request = ServletActionContext.getRequest();
private HttpServletResponse response = ServletActionContext.getResponse();
private ASPAdminModifyBean modify = new ASPAdminModifyBean();
GetRolePermissionListInt role;
//getters and setters for the above
public String grantRolesPermissions(){
System.out.println("enter the grant roles and permissions");
String tab2="modify";
boolean id;
HttpServletRequest request=getRequest();
HttpSession session=request.getSession();
session.setAttribute("tabs",tab2 );
role=aspService.getGrantedRolesAndPermissions(modify);
System.out.println("assigned roles===================>"+role.getAssignedRoles());
modify.setAspmodifyassignedRole(role.getAssignedRoles());
modify.setAspmodifyassignedPermission(role.getAssignedPermissions());
modify.setCreatedby(role.getCreatedBy());
modify.setCreateddate(role.getCreatedDate());
modify.setUpdatedby(role.getUpdatedBy());
modify.setUpdateddate(role.getUpdatedDate());
modify.setUsername(role.getUserName());
modify.setModifyftid(role.getFtid());
System.out.println("assigned permissions==============>"+role.getAssignedPermissions());
System.out.println("updated by=================>"+role.getUpdatedBy());
System.out.println("update date=================>"+role.getUpdatedDate());
System.out.println("created by===================>"+role.getCreatedBy());
System.out.println("created date=====================>"+role.getCreatedDate());
System.out.println("ftid=============================>"+role.getFtid());
System.out.println("user name===========================>"+role.getUserName());
System.out.println("ftid=============>"+role.getFtid());
if(role!=null){
return SUCCESS;
}else{
return ERROR;
}
}
#Override
public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub
}
#Override
public ASPAdminModifyBean getModel() {
// TODO Auto-generated method stub
return modify;
}
}
Well, the code is grown again :)
Start by :
changing your ArrayList declarations to List (in both beans, and regenerate getters and setters);
changing the way you get the Request, the Response and the Session, by using Struts2 Aware s interfaces (and their setters, with code inside)
Then if it still doesn't work, describe a little better what do you mean by "values are not passing to Action", and consider posting your interceptor stack config.
Hope that helps...
i am quite new at this and i what to know how can i get a index row from a dynamical table created with struts2. Here is what i have tried so far:
test file
<table class="table table-bordered table-striped table-condensed table-hover"
id="exp">
<thead>
<tr>
<th class="center"></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<s:if test="listanume.size>0">
<s:iterator value="listanume" status="statusVar">
<tr>
<td class="center">
<button class="btn" onclick="javascript:setval(0)">
delete
</button>
</td>
<td><s:property value="nume"/></td>
</tr>
</s:iterator>
</s:if>
</tbody>
</table>
<h4>Numarul randului este: <s:property value="mysample"/> </h4>
<script>
var mysample= '';
function= setval(varval){
mysample=varval;
alert(mysample);
}
</script>
pop java
public class Pop {
private int nrrow;
private List<UserModel> listanume = new ArrayList<UserModel>();
UserModel user = new UserModel(),
user1 = new UserModel(),
user2 = new UserModel();
private String[] sample;
{
sample = new String[]{"list1", "list2", "list3"};
}
public String execute() {
user.setEmail("eret#esre");
user.setPass1("1234");
user.setNume("gigel");
user1.setEmail("yuii#ihj");
user1.setPass1("6789");
user1.setNume("marius");
user2.setEmail("nmnn#cvx");
user2.setPass1("7676");
user2.setNume("sorin");
sample1.add(user);
sample1.add(user1);
sample1.add(user2);
return "succes";
}
public String afisnrow(){
execute();
listanume=sample1;
return "succes";
}
public String[] getSample() {
return sample;
}
public void setSample(String[] sample) {
this.sample = sample;
}
public List<UserModel> getSample1() {
return sample1;
}
public void setSample1(List<UserModel> sample1) {
this.sample1 = sample1;
}
public void setNrrow(int nrrow){
this.nrrow=nrrow;
}
public int getNrrow(){
return nrrow;
}
public List<UserModel> getListanume(){
return listanume;
}
public void setListanume(List<UserModel> listanume){
this.listanume=listanume;
}
}
every row has a button on it and when i click that button i need to get the row index, i kind of stuck and run out of ideas, any suggestions?
replace
onclick="javascript:setval(0)"
with
onclick="javascript:setval(<s:property value="#statusVar.index" />)"
more info on the struts2 iterator tag here.
The solution i have found is this:
test file
<table class="table table-bordered table-striped table-condensed table-hover"
id="exp">
<thead>
<tr>
<th class="center"></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<s:if test="listanume.size>0">
<s:iterator value="listanume" status="statusVar">
<tr>
<td class="center">
<button class="btn" id="<s:property value='indexrow'/>">
delete
</button>
</td>
<td><s:property value="nume"/></td>
</tr>
</s:iterator>
</s:if>
</tbody>
</table>
<i><p id="test"> No button pressed.</p></i>
<script>
$("button").click(function(e){
var idClicked = e.target.id;
$("#test").html(idClicked);
});
</script>
pop java
public class Pop {
private int indexrow;
private List<UserModel> listanume = new ArrayList<UserModel>();
UserModel user = new UserModel(),
user1 = new UserModel(),
user2 = new UserModel();
public String execute() {
user.setEmail("eret#esre");
user.setPass1("1234");
user.setNume("gigel");
user1.setEmail("yuii#ihj");
user1.setPass1("6789");
user1.setNume("marius");
user2.setEmail("nmnn#cvx");
user2.setPass1("7676");
user2.setNume("sorin");
listanume.add(user);
listanume.add(user1);
listanume.add(user2);
return "succes";
}
public String afisnrow(){
execute();
for (UserModel userModel : listanume) {
UserModel userModel1=new UserModel();
indexrow++;
userModel1.setNume(userModel.getNume());
userModel1.setIndexrow(indexrow);
listanume.add(userModel1);
}
return "succes";
}
public List<UserModel> getListanume(){
return listanume;
}
public void setListanume(List<UserModel> listanume){
this.listanume=listanume;
}
}