Dropdown Excel dengan Range Source

February 2, 2020 Leave a comment

Jika list data yang akan kita gunakan sedikit menuliskan values list data di bagian Source pada pop up Data Validation tidak akan menjadi masalah sepert pada post ini. Namun akan menyulitkan jika kita values list data tersebut banyak. Untuk hal tersebut kita bisa menggunakan referense source, dimana reference source dapat diletakan pada sheet yang sama atau sheet yang berbeda.

Berikut langkah-langkah membuat dropdown range source di Excel

  1. Buat values list yang akan digunakan untuk dropdown

2. Langkah selanjutnya mirip dengan cara pada post sebelumnya. Bedanya pada field Source pada pop up Data Validation gunakan referensi absolut yang mengarah pada range list data yang telah kita buat

3. Berikut contoh hasil

Terima kasih 🙂

Categories: Excel Tips Tags: ,

Dropdown Excel

January 2, 2020 1 comment

Langkah-langkah membuat dropdown di Excel :

  1. Pilih cell dimana dropdown list akan ditampilkan
  2. Pilih menu Data Validation pada tab Data

3. Setelah itu muncul pop up Data Validation pada bagian tab setting field Allow pilih List.

4. Pada field source, isi list atau daftar pilihan data yang akan diijinkan dengan koma sebagai pemisah.

5. Berikut contoh hasil

Terima kasih.

Categories: Excel Tips Tags: ,

Morning Scenery

September 16, 2019 Leave a comment

Morning Scenery

Categories: Ren's Notes Tags:

Binding List of Object in Spring MVC

April 16, 2018 Leave a comment

This post is about how to binding list of object in Spring MVC.

Model class

import java.io.Serializable;
public class RiskProfileWeight implements Serializable{

private static final long serialVersionUID = -6333729214026949719L;

private Integer component;
private String riskProfile;
private String description;
private Integer month;
private Integer year;
private Double weightInheren;
private Double weightKpmr;

public Integer getComponent() {
return component;
}
public void setComponent(Integer component) {
this.component = component;
}
public String getRiskProfile() {
return riskProfile;
}
public void setRiskProfile(String riskProfile) {
this.riskProfile = riskProfile;
}

public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getMonth() {
return month;
}
public void setMonth(Integer month) {
this.month = month;
}
public Integer getYear() {
return year;
}
public void setYear(Integer year) {
this.year = year;
}
public Double getWeightInheren() {
return weightInheren;
}
public void setWeightInheren(Double weightInheren) {
this.weightInheren = weightInheren;
}
public Double getWeightKpmr() {
return weightKpmr;
}
public void setWeightKpmr(Double weightKpmr) {
this.weightKpmr = weightKpmr;
}
}

To bind list of object we need some wrapper class. In wrapper class constructor we need initialize list of object that we want to bind.
Wrapper class

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class RiskProfileWeightWrapper implements Serializable{
private static final long serialVersionUID = -2676440868027538643L;

private List listRiskProfileWeight;

public RiskProfileWeightWrapper(){
listRiskProfileWeight = new ArrayList();
}

public List getListRiskProfileWeight() {
return listRiskProfileWeight;
}

public void setListRiskProfileWeight(List listRiskProfileWeight) {
this.listRiskProfileWeight = listRiskProfileWeight;
}

}

Controller class, this is no complete code.

.....
@RequestMapping(value = "/weightIntegrationConsolidation.html", method = {RequestMethod.GET})
public ModelAndView weightIntegrationConsolidation(@ModelAttribute("riskProfileWeightWrapper") RiskProfileWeightWrapper riskProfileWeightWrapper){
mv = new ModelAndView("page.history.weight.integration.consolidation");
try {
List listRiskProfileWeight = getListModelFromDb();
riskProfileWeightWrapper.setListRiskProfileWeight(listRiskProfileWeight);
} catch (Exception e) {

}
return mv;
}

@RequestMapping(value = "/weightIntegrationConsolidation.html", method = {RequestMethod.POST})
public ModelAndView weightIntegrationConsolidationSaveUpdate(@ModelAttribute("riskProfileWeightWrapper") RiskProfileWeightWrapper riskProfileWeightWrapper) {
mv = new ModelAndView("page.history.weight.integration.consolidation");
try {

} catch (Exception e) {

}
return mv;
}
.....

View using JSP

....
<div class="row">
<div class="col-xs-12">
        <table id="statusTable" class="table mnc-table" style="table-layout: auto;width: 650px; ">
                            <thead>
                                <tr>
                                   <th width="10%">OKR</th>
                                   <th width="5%">ACD</th>
                                   <th width="5%">DEF</th>
                                </tr>
                            </thead>
                            <c:set var="id" value="${0}"></c:set>
                            <c:forEach items="${riskProfileWeightWrapper.listRiskProfileWeight}" var="el">
                            <tr>
                               <td>${el.description}</td>
                               <td>                                                                  
                                  <input type="text" class="form-control" name="listRiskProfileWeight[${id}].weightInheren" id="listRiskProfileWeight[${id}].weightInheren"  value="${riskProfileWeightWrapper.listRiskProfileWeight[id].weightInheren}"/>
                               </td>
                               <td>
                                  <input type="text" width="5" class="form-control" name="listRiskProfileWeight[${id}].weightKpmr" id="listRiskProfileWeight[${id}].weightKpmr"  value="${riskProfileWeightWrapper.listRiskProfileWeight[id].weightKpmr}" maxlength="5"/>
                               </td>
                               <input type="hidden" class="form-control" name="listRiskProfileWeight[${id}].riskProfile" id="listRiskProfileWeight[${id}].riskProfile"  value="${riskProfileWeightWrapper.listRiskProfileWeight[id].riskProfile}" />
                               <input type="hidden" class="form-control" name="listRiskProfileWeight[${id}].description" id="listRiskProfileWeight[${id}].description"  value="${riskProfileWeightWrapper.listRiskProfileWeight[id].description}"/>
                               <input type="hidden" class="form-control" name="listRiskProfileWeight[${id}].ljkNo" id="listRiskProfileWeight[${id}].ljkNo"  value="${selectedLjkNo}" />
                               <input type="hidden" class="form-control" name="listRiskProfileWeight[${id}].month" id="listRiskProfileWeight[${id}].month"  value="${monthFirst}"/>
                               <input type="hidden" class="form-control" name="listRiskProfileWeight[${id}].year" id="listRiskProfileWeight[${id}].year"  value="${yearFirst}" />
                               
                            </tr>
                            <c:set var="id" value="${id + 1}"></c:set> 
                            </c:forEach>
                            
                            <tbody>
                            </tbody>
                    </table>
</div>
</div>
....

Thank you. 🙂

Equals Method for Objects in Java

March 24, 2018 Leave a comment

This post is about how to compare object based on their fields and return true if they’re equal. To achieve this, we must override equals AND hashCode method.

Below the example.


public class Book {

private int id;
private String title;
private String author;

public Book(){
}

public Book(int id, String title, String author){
this.id = id;
this.title = title;
this.author = author;
}

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}

@Override
public boolean equals(Object obj) {
if (obj == null)
return false;

if (!(obj instanceof Book))
return false;

if (obj == this)
return true;

if (this.getTitle().equals(((Book) obj).getTitle()) && this.getTitle().equals(((Book) obj).getTitle())) {
return true;
} else {
return false;
}
}

@Override
public int hashCode() {
final int prime = 41;
int result = 1;
result = prime * result + ((this.getAuthor() == null) ? 0 : this.getAuthor().hashCode());
result = prime * result + ((this.getTitle() == null) ? 0 : this.getTitle().hashCode());
return result;
}
}

in piece code above, object is considered equal if field author and title have same value.

public static void main( String[] args )
{

Book firstBook = new Book(1, "Supernova", "Dee Lestari");
Book secondBook = new Book(2, "Supernova", "Dee Lestari");
Book thirdBook = new Book(3, "Aroma Karsa", "Dee Lestari");

List<Book> books = new ArrayList<Book>();
books.add(firstBook);

System.out.println("Is First equals Second book: "+firstBook.equals(secondBook));
System.out.println("Is First equals Third book: "+firstBook.equals(thirdBook));
System.out.println("Is Books List Containts Second book: "+books.contains(secondBook));
System.out.println("Is Books List Containts third book: "+books.contains(thirdBook));}

Result :

Equals Override Result

 

Overriding hashCode method.

The purpose overriding this method is if work with Java Hashed Collection, object that has same field value ( in this case title and author field) considered equal.

Let’s say, we don’t override hashCode method.

 
public static void main( String[] args ) {

Book firstBook = new Book(1, "Supernova", "Dee Lestari");
Book secondBook = new Book(2, "Supernova", "Dee Lestari");
Book thirdBook = new Book(3, "Aroma Karsa", "Dee Lestari");

HashSet <Book> hashBooks = new HashSet <Book> ();
hashBooks.add(firstBook);
hashBooks.add(secondBook);
hashBooks.add(thirdBook);
System.out.println("HashSet size: " + hashBooks.size());
}

Result:

HashCode Method Is Not Overrided

As you see, hashBooks variable containts 3 element, HashSet consider them as different object. We expect 2 element since object firstBook and secondBook has same field value.

Conclusion

  • It is mandatory to override hashcode() each time we override equals()
  • If two objects are equal, they MUST have the same hash code

Thank you. 😀

Customize 403 Access Denied Spring Security

February 23, 2018 1 comment

In this post, I will show you how to add customize 403 access denied page in spring security. I use project in another post as basis.

1. Add 403 page

<html>
<body>
 <h1>HTTP Status 403 - Access is denied</h1>
 <h2>${msg}</h2>
</body>
</html>

2.Add a mapping for “/403” url in controller

 @RequestMapping(value = "/403", method = RequestMethod.GET)
 public ModelAndView aaccessDenied(Principal user) {
 mv = new ModelAndView("403");
 if (user != null) {
 mv.addObject("msg", "Hi " + user.getName()
 + ", you do not have permission to access this page!");
 } else {
 mv.addObject("msg",
 "You do not have permission to access this page!");
 }
 return mv;
 }

3.Add custom class to handle 403
In this class we can perform some logic before we redirect request to 403 page

</pre>
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

public class CustomAccessDeniedHandler implements AccessDeniedHandler {

private String accessDeniedPage= "403";
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exception)
throws IOException, ServletException {
System.out.println("Logic in here");
response.sendRedirect(accessDeniedPage);
}
}

4. Edit Spring Security config xml

	<http auto-config="true">
	<access-denied-handler ref="customAccessDeniedHandler" />
         ...
	</http>

        <beans:bean id="customAccessDeniedHandler"  class="org.mvc.security.config.CustomAccessDeniedHandler" />

5. Screen shoot

403

Spring Security Form Login With Database

January 28, 2018 1 comment

In this post, we will show you how to perform authentication using Spring Security backed by database.

Technology stack

  • Spring 4.2.5.RELEASE
  • Spring Security 4.2.3.RELEASE
  • Maven
  • Hibernate 5.2.5.Final
  • MySQL Database
  • Eclipse

Project structure

Project Structure

Below details step.

  • User entity
</pre>

package org.mvc.security.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
* The Class User.
*/
@Entity
@Table(name = "users")
public class User {

/** The id. */
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

/** The username. */
@Column(name = "username")
private String username;

/** The password. */
@Column(name = "password")
private String password;

/** The password confirm. */
@Transient
private String passwordConfirm;

/** The roles. */
@ManyToMany(cascade = CascadeType.REMOVE, fetch =FetchType.EAGER)
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
private List<Role> roles;

/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}

/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}

/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}

/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Gets the password.
*
* @return the password
*/
public String getPassword() {
return password;
}

/**
* Sets the password.
*
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}

/**
* Gets the roles.
*
* @return the roles
*/
public List<Role> getRoles() {
return roles;
}

/**
* Sets the roles.
*
* @param roles the new roles
*/
public void setRoles(List<Role> roles) {
this.roles = roles;
}

/**
* Gets the password confirm.
*
* @return the password confirm
*/
public String getPasswordConfirm() {
return passwordConfirm;
}

/**
* Sets the password confirm.
*
* @param passwordConfirm the new password confirm
*/
public void setPasswordConfirm(String passwordConfirm) {
this.passwordConfirm = passwordConfirm;
}

}
  • Role entity

package org.mvc.security.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
* The Class Role.
*/
@Entity
@Table(name = "roles")
public class Role {

/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

/** The name. */
@Column(name = "name")
private String name;

/** The users. */
@ManyToMany(mappedBy = "roles", fetch = FetchType.EAGER)
private List<User> users;

/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}

/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}

/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets the users.
*
* @return the users
*/
public List<User> getUsers() {
return users;
}

/**
* Sets the users.
*
* @param users the new users
*/
public void setUsers(List<User> users) {
this.users = users;
}

}

  • Spring context

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

<context:annotation-config/>
<bean id="springDatasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${jdbc.url}" />
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="springDatasource" />
<property name="packagesToScan" value="org.mvc.security.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
</props>
</property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>

* Spring security xml configuration

</pre>

<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd">

<http auto-config="true">
<csrf disabled="true"/>
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/login*" access="isAnonymous()" />
<intercept-url pattern="/user/**" access="hasAuthority('USER')" />
<intercept-url pattern="/admin/**" access="hasAuthority('ADMIN')" />

<form-login login-page="/login" authentication-success-handler-ref="customSuccessHandler" authentication-failure-url="/login?error=true" username-parameter="username" password-parameter="password" />
<logout logout-success-url="/login?logout=true" />
</http>

<beans:bean id="customSuccessHandler" class="org.mvc.security.config.CustomSuccessHandler" />

<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsService">
</authentication-provider>
</authentication-manager>

</beans:beans>

* Create database with hibernate name and edit user and password for MySql database at application.properties file respectively. Table user and role will be created automatically

* Run this sql script


insert into roles (name) values ('USER');
insert into roles (name) values ('ADMIN');

insert into users (password, username) values ('12345', 'User');
insert into users (password, username) values ('12345', 'Admin');

insert into users_roles (user_id, role_id) values (1,1);
insert into users_roles (user_id, role_id) values (2,2);

* Add security filter in web.xml file

 <filter>
 <filter-name>springSecurityFilterChain</filter-name>
 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>springSecurityFilterChain</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping

* Login form

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<div class="container">
<form class="form-horizontal" method="post" action="login" >
 <h2>Login Form</h2>
 <div class="form-group">
 <label class="control-label col-sm-2" for="username">Username</label>
 <div class="control-label col-sm-8">
 <input type="text" class="form-control" id="username" name="username" placeholder="Type Username"/>
 </div>
 </div>
 
 <div class="form-group">
 <label class="control-label col-sm-2" for="password">Password</label>
 <div class="control-label col-sm-8">
 <input type="password" class="form-control" id="password" name="password" placeholder="Type Password"/>
 </div>
 </div>
 <span>${error}</span>
 <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
 <button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>

* Screen shoot

Login Form

 

You can get complete code in here

Hope it will help.

Thank you.

Split List of Object to Map of Sub List object in Java

October 25, 2017 Leave a comment

Firstly, let’s model the element:

public class User {
private Long id;
private String userName;
private Long departmentId;
/*getter setter method*/
}

So this is how split list to map of sub list and department id as key map.

public Map<Long , List<User>> splitList() {
     Long key;
     List<User> listOfSubUser;
     Map<Long, List<User>> mapOfUser = new HashMap<Long, List<User>>();
     List<User> ListOfUser = /*Get list from some source*/;

     for(User user: ListOfUser){
       key = user.getDepartmentId();
       listOfSubUser= mapOfUser.get(key);
       if(listOfSubUser == null){
	   listOfSubUser= new ArrayList<User>();
       }
       listOfSubUser.add(user);
       mapOfRoleUrlAddress.put(key,listOfSubUser);
       }

     return mapOfUser;
   }

I hope this helps 🙂

Binding List Of Object In Spring MVC

September 9, 2017 Leave a comment

Goal in this post is binding list of object from user input and send it to back.

Initial Page

 

Add Element Object

Result

 

Code is below.

Domain class (User.java)

import java.io.Serializable;
public class User implements Serializable{

private static final long serialVersionUID = -830070182483354365L;

private Long userNo;
private String username;
private String email;

public Long getUserNo() {
return userNo;
}

public void setUserNo(Long userNo) {
this.userNo = userNo;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}

Wrapper class (UserWrapper.java)

public class UserWrapper implements Serializable{
private static final long serialVersionUID = -8784765152648277985L;

private List<User> listUser;

public List<User> getListUser() {
return listUser;
}

public void setListUser(List<User> listUser) {
this.listUser = listUser;
}
}

Controller class (HomeController.java)

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.mandiri.r3e.r3e.domain.UserWrapper;

@Controller
public class HomeController {

	private ModelAndView mv;
	
	@RequestMapping(value="/")
	public ModelAndView test(HttpServletResponse response) throws IOException{
		mv =  new ModelAndView("home");
		return mv;
	}
	
	@RequestMapping(value="/add-user.html", method = RequestMethod.GET)
	public ModelAndView addUser(@ModelAttribute("userWrapper") UserWrapper userWrapper){
		mv =  new ModelAndView("add.user");
		return mv;
	}
	
	@RequestMapping(value = "add-user.html", method = RequestMethod.POST)
	public ModelAndView addUserProcess(@ModelAttribute("userWrapper") UserWrapper userWrapper) {
		mv = new ModelAndView("redirect:/add-user.html");
		try {
	      System.out.println("Size List User: "+userWrapper.getListUser().size());
		} catch (Exception e) {

		}
		return mv;
	}
}

View code (add.user.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<script type="text/javascript">
$(document).ready(function(){
var id = 0;
$("#addBtn").click(function(){
var number = id +1;
$("#user-list").append(
'<div id="div-'+id+'" >'+
number +'. '+
'<input name="listUser['+id+'].username" id="listUser['+id+'].username" value="" placeholder="username"/>'+
'<input name="listUser['+id+'].email" id="listUser['+id+'].email" value="" placeholder="email"/>'+
'<div>');
id = id +1;
});
});

function save(){
var context = '${pageContext.request.contextPath}';
url = context +'/add-user.html';
$("#workForm").attr('action', url);
$("#workForm").submit();
};

</script>

<form:form id="workForm" modelAttribute="userWrapper" method="POST">
<input type="button" id="addBtn" value="Add User"/>
</br>
<div id="user-list">

</div>
</br>
</br>
<input type="button" id="submitBtn" value="Save" onclick="save();" />
</form:form>

Hope this helps. 🙂