java.lang.IndexOutOfBoundsException: Index 16 out of bounds for length 10 Error - spring

I encountered the following error during the posting paging process. I don't even use an array, but I don't know why I get this error. How can I solve this?
BoardCriteria is an object that stores the information needed to page the bulletin list.
java.lang.IndexOutOfBoundsException: Index 16 out of bounds for length 10
controller
// http://localhost:8088/club/{club_no}/boards
// http://localhost:8088/club/1/boards
#RequestMapping(value = "/{club_no}/boards", method = RequestMethod.GET)
public String boardListAllGet(#PathVariable("club_no") Integer club_no, Model model, BoardCriteria cri) {
log.info("club_no : "+club_no);
List<BoardTotalBean> boardList = service.getBoardListAll(club_no, cri);
log.info("############"+boardList.get(16)+"");
model.addAttribute("club_no", club_no);
model.addAttribute("boardList", service.getBoardListAll(club_no, cri));
//BoardPageMaker pageMarker = new BoardPageMaker();
//pageMarker.setCri(cri);
//pageMarker.setTotalCount(service.getTotalBoardCnt());
//log.info(pageMarker+"");
//model.addAttribute("pm", pageMarker);
return "/club/boards/boardList";
}
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.joinus.mapper.ClubMapper">
<resultMap type="MembersVo" id="membersMap">
<id property="member_no" column="member_no"/>
<id property="member_email" column="member_email"/>
<id property="member_pass" column="member_pass"/>
<id property="member_name" column="member_name"/>
<id property="member_location" column="member_location"/>
<id property="member_tel" column="member_tel"/>
<id property="member_image" column="member_image"/>
<id property="member_regdate" column="member_regdate"/>
<id property="member_updatedate" column="member_updatedate"/>
<id property="member_authority" column="member_authority"/>
<id property="member_signup_type" column="member_signup_type"/>
<id property="member_status" column="member_status"/>
<id property="member_role" column="member_role"/>
<id property="member_type" column="member_type"/>
<id property="member_location" column="member_location"/>
</resultMap>
<resultMap type="ClubBoardsVo" id="clubBoardsMap">
<id property="club_board_no" column="club_board_no"/>
<id property="club_no" column="club_no"/>
<id property="board_type_no" column="board_type_no"/>
<id property="member_no" column="member_no"/>
<id property="club_board_title" column="club_board_title"/>
<id property="club_board_content" column="club_board_content"/>
<id property="club_board_image" column="club_board_image"/>
<id property="club_board_date" column="club_board_date"/>
<id property="club_board_updatedate" column="club_board_updatedate"/>
<id property="club_board_likecnt" column="club_board_likecnt"/>
<id property="club_board_commentcnt" column="club_board_commentcnt"/>
</resultMap>
<resultMap type="BoardTotalBean" id="boardListMap">
<collection property="membersVo" resultMap="membersMap"/>
<collection property="clubBoardsVo" resultMap="clubBoardsMap" />
</resultMap>
<select id="getBoardListAll" resultMap="boardListMap">
<![CDATA[
select b.club_board_no, m.member_name, m.member_image, b.club_board_title, b.club_board_content, b.club_board_image, b.club_board_date, b.club_board_updatedate, b.club_board_likecnt, b.club_board_commentcnt
from club_boards b
join members m
on (b.member_no = m.member_no)
where b.club_no = #{club_no}
order by club_board_no desc
limit #{pageStart}, #{perPageNum}
]]>
</select>
<select id="totalBoardCnt" resultType="java.lang.Integer">
select count(club_board_no) from club_boards
</select>
</mapper>
DAOImpl
package com.joinus.persistence;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.joinus.domain.BoardCommentsVo;
import com.joinus.domain.BoardCriteria;
import com.joinus.domain.BoardLikesVo;
import com.joinus.domain.BoardTotalBean;
import com.joinus.domain.ClubBoardsVo;
import com.joinus.domain.ClubMembersVo;
import com.joinus.domain.ClubTotalBean;
import com.joinus.domain.ClubsVo;
import com.joinus.domain.Criteria;
import com.joinus.domain.MembersVo;
#Repository
public class ClubDaoImpl implements ClubDao{
#Inject
private SqlSession sqlSession;
static final String NAMESPACE ="com.joinus.mapper.ClubMapper";
public List<BoardTotalBean> getBoardListAll(Integer club_no, BoardCriteria cri) {
log.info("######"+club_no+", "+cri);
Map<String, Object> param = new HashMap<String, Object>();
param.put("club_no", club_no);
param.put("pageStart", cri.getPageStart());
param.put("perPageNum", cri.getPerPageNum());
return sqlSession.selectList(NAMESPACE+".getBoardListAll", param);
}
}
BoardCriteria
package com.joinus.domain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BoardCriteria {
private static final Logger log = LoggerFactory.getLogger(BoardCriteria.class);
private int page;
private int perPageNum;
public BoardCriteria() {
this.page = 1;
this.perPageNum = 10;
}
public void setPage(int page) {
if(page <= 0) {
this.page = 1;
return;
}
this.page = page;
}
public void setPerPageNum(int perPageNum) {
if(perPageNum <=0 || perPageNum > 100) {
this.perPageNum = 10;
return;
}
this.perPageNum = perPageNum;
}
public int getPageStart() {
return (this.page - 1) * perPageNum;
}
public int getPage() {
return page;
}
public int getPerPageNum() {
return perPageNum;
}
// alt shift s + s
#Override
public String toString() {
return "BoardCriteria [page=" + page + ", perPageNum=" + perPageNum + "]";
}
}

It seems there is a limit of 10 in BoardCriteria:
public BoardCriteria() {
this.page = 1;
this.perPageNum = 10;
}
This might pose a problem when you attempt to access item 16:
List<BoardTotalBean> boardList = service.getBoardListAll(club_no, cri);
log.info("############"+boardList.get(16)+"");

Related

returning MyBatis resultMap as map

I have a mybatis resultMap refer to a POJO class as like below.
<resultMap id="FolderResultMap" type="Folder">
<result column="recordcount" property="recordCount" />
<result column="contenttype" property="folderContentType" />
<result column="folderid" property="folderId" />
<result column="folderdesc" property="folderDescription" />
<result column="foldername" property="folderName" />
<result column="foldertype" property="folderType" />
</resultMap>
<select id="findReportFolders" resultMap="FolderResultMap">
some query
</select>
And in my Mapper interface
List<Folder> findReportFolders (#Param("name") long id,
#Param("id2") long busid);
Because of this i am getting JSON response as list of objects where i need map of list of objects as below mentioned.
{
"folders": [
{
"recordCount": 7,
"folderContentType": "Reports",
"folderId": 139491,
"folderDescription": null,
"folderName": "AA_TestPrivateFolder1234",
"folderType": "CUSTOM",
"refreshable": true
},
{
"recordCount": 35,
"folderContentType": "Reports",
"folderId": 140109,
"folderDescription": "Default Folder for New Reports",
"folderName": "label.privateReportInboxOverrideName",
"folderType": "INBOX",
"refreshable": true
}]
}
This what i am getting now. I would like to get the response as above.
[{"folderId":359056,"folderName":"BE Shared Report Inbox","folderDescription":"BE Shared Report Inbox","folderType":"INBOX","folderContentType":"SharedReports","recordCount":0,"refreshable":true},{"folderId":363984,"folderName":"Default Inbox Folder","folderDescription":"Default Folder for New Reports","folderType":"INBOX","folderContentType":"Reports","recordCount":0,"refreshable":true}]
Any Idea how can i do this?
Nothing in your example JSON requires a Map of anything.
Instead,
create an object hierarchy that represents the JSON structure that you need and use Jackson (or some other JSON library) to generate the JSON.
Here is some example code that uses Jackson:
package blam.won;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Blam
{
#JsonProperty
private String folderContentType;
#JsonProperty
private int recordCount;
public void setFolderContentType(
final String newValue)
{
folderContentType = newValue;
}
public void setRecordCount(
final int newValue)
{
recordCount = newValue;
}
}
package blam.won;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Kapow
{
#JsonProperty("folders")
private List<Blam> blamList;
public void setBlamList(
final List<Blam> newValue)
{
blamList = newValue;
}
}
package blam.won;
import java.util.LinkedList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TestWon
{
private ObjectMapper objectMapper;
#Before
public void preTestSetup()
{
objectMapper = new ObjectMapper();
}
#Test
public void testKapow()
throws JsonProcessingException
{
final Blam blam1 = new Blam();
final Blam blam2 = new Blam();
final List<Blam> blamList = new LinkedList<>();
final String jsonString;
final Kapow kapow = new Kapow();
blam1.setFolderContentType("Reports");
blam1.setRecordCount(7);
blamList.add(blam1);
blam2.setFolderContentType("Reports");
blam2.setRecordCount(35);
blamList.add(blam2);
kapow.setBlamList(blamList);
jsonString = objectMapper.writeValueAsString(kapow);
System.out.println(jsonString);
}
}

How to add a NameId value to a AttributeValue using OpenSAML2

Using OpenSAML2 how does one create the following XML:
<saml:Attribute Name="urn:mace:dir:attribute-def:eduPersonTargetedID"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml:AttributeValue>
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">c693b1c47a0da7de6518bc30a1bb8d2e44b56980</saml:NameID>
</saml:AttributeValue>
</saml:Attribute>
Extending OpenSAML fixes the issue as it doesn't seem to support NameID values within Attribute Value elements.
The following files are required to implement the AttributeValue.
Builder
package com.blah;
import org.opensaml.common.impl.AbstractSAMLObjectBuilder;
import org.opensaml.common.xml.SAMLConstants;
import org.opensaml.saml2.core.AttributeValue;
public class AttributeValueBuilder extends AbstractSAMLObjectBuilder<AttributeValue>{
public AttributeValueBuilder() {
}
#Override
public AttributeValue buildObject() {
return buildObject(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
}
#Override
public AttributeValue buildObject(String namespaceURI, String localName, String namespacePrefix) {
return new AttributeValueImpl(namespaceURI, localName, namespacePrefix);
}
}
Implementation
package com.blah;
import java.util.ArrayList;
import java.util.List;
import org.opensaml.common.impl.AbstractSAMLObject;
import org.opensaml.xml.XMLObject;
public class AttributeValueImpl extends AbstractSAMLObject implements org.opensaml.saml2.core.AttributeValue{
protected AttributeValueImpl(String namespaceURI, String elementLocalName,
String namespacePrefix) {
super(namespaceURI, elementLocalName, namespacePrefix);
}
private List<XMLObject> children = new ArrayList<XMLObject>();
#Override
public List<XMLObject> getOrderedChildren() {
return children;
}
}
Marshaller
package com.blah;
import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
public class AttributeValueMarshaller extends AbstractSAMLObjectMarshaller {
}
Unmarshaller
package com.blah;
import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
import org.opensaml.xml.XMLObject;
import org.opensaml.xml.io.UnmarshallingException;
public class AttributeValueUnmarshaller extends AbstractSAMLObjectUnmarshaller {
#Override
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
throws UnmarshallingException {
AttributeValueImpl attributeValue = (AttributeValueImpl) parentSAMLObject;
attributeValue.getOrderedChildren().add(childSAMLObject);
}
}
Once these files are included they need to be added to the OpenSAML bootstrapping configuration file saml2-assertion-config.xml (I copied it from the OpenSAML jar and placed it into the root of the Java src):
<!-- AttributeValue -->
<ObjectProvider qualifiedName="saml2:AttributeValue">
<BuilderClass className="com.blah.AttributeValueBuilder" />
<MarshallingClass className="com.blah.AttributeValueMarshaller" />
<UnmarshallingClass className="com.blah.AttributeValueUnmarshaller" />
</ObjectProvider>
<ObjectProvider qualifiedName="saml2:AttributeValueType">
<BuilderClass className="com.blah.AttributeValueBuilder" />
<MarshallingClass className="com.blah.AttributeValueMarshaller" />
<UnmarshallingClass className="com.blah.AttributeValueUnmarshaller" />
</ObjectProvider>
It is now possible to add any element to the Attribute Value body.
private static XMLObject createAttributeValueNameId(String value) throws ConfigurationException {
XMLObjectBuilder<AttributeValueImpl> attrBuilder = getSamlBuilder().getBuilder(AttributeValue.DEFAULT_ELEMENT_NAME);
AttributeValueImpl attributeValue = attrBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
XMLObjectBuilder<AttributeValue> builder = getSamlBuilder().getBuilder(NameID.DEFAULT_ELEMENT_NAME);
NameID nameId = (NameID) builder.buildObject(NameID.DEFAULT_ELEMENT_NAME);
nameId.setFormat(NameID.UNSPECIFIED);
nameId.setValue(value);
attributeValue.getOrderedChildren().add(nameId);
return attributeValue;
}

Is it possible to define a Spring Repository for shared classes?

I have a class User which is shared between the server and the android client. So I don't want to annotate the class with an #id annotation.
What is the best way to deal with this in spring-jpa?
I believe the simplest possible way is to fallback to xml mapping so your domain objects will stay pure.
Spring-boot will notice that you're using this type of mapping and configure hibernate for you out of the box.
Here is a simple example:
package com.stackoverflow.so45264894;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.repository.CrudRepository;
#SpringBootApplication
#EnableJpaRepositories
public class So45264894Application {
public static void main(String[] args) {
SpringApplication.run(So45264894Application.class, args);
}
public static class User {
private Long id;
private String username;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
}
#Bean
CommandLineRunner run(UserRepository userRepository) {
final User user = new User();
user.setUsername("admin");
return args -> userRepository.save(user);
}
}
interface UserRepository extends CrudRepository<So45264894Application.User, Long> {
}
And mapping from /src/main/resources/com/stackoverflow/so45264894/User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.stackoverflow.so45264894" default-access="field">
<class name="com.stackoverflow.so45264894.So45264894Application$User" table="users" dynamic-update="true">
<id name="id" type="java.lang.Long">
<column name="user_id" sql-type="integer"/>
<generator class="identity"/>
</id>
<property name="username" column="username" unique="true"/>
</class>
</hibernate-mapping>
Output:
Hibernate: drop table users if exists
Hibernate: create table users (user_id integer generated by default as identity, username varchar(255), primary key (user_id))
Hibernate: alter table users add constraint UK_r43af9ap4edm43mmtq01oddj6 unique (username)
Hibernate: insert into users (username, user_id) values (?, ?) // <- this is userRepository.save() call

Error reading 'nom' on type dao.Etudiant_$$_jvst1a2_0 Hibernate

I want to search on a table by ID , the search work fine , but when hibernate don t find any row it s return this error :
Error reading "nom" on type dao.Etudiant , and sometimes it s return : No row with the given identifier exists:[dao.Etudiant#4]
I want to show nothing when hibernate don t find that ID on the table , need your helps thanks , I m stack my learning, I googled a lot without any solution. this is my code :
Controller :
package controller;import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import dao.DaoEtudiant;
import dao.Etudiant;
import service.EtudiantMetier;
#Controller
public class EtudiantController {
#Autowired
EtudiantMetier service;
#RequestMapping("afficherId")
public String afficheId(Model mod,#RequestParam(value="id") Long id)
{
List <Etudiant> ets1=new ArrayList<Etudiant>();
ets1.add(service.chercheEtudiantID(id));
mod.addAttribute("etudiants",ets1);
return "etudiant1";
}
}
Class : Etudiant :
package dao;
import java.util.Date;
public class Etudiant {
private Long idEtudiant;
private String nom;
private String prenom;
private Date dateNaissance;
private String email;
public Etudiant() {
super();
}
public Long getIdEtudiant() {
return idEtudiant;
}
public void setIdEtudiant(Long idEtudiant) {
this.idEtudiant = idEtudiant;
}
public Etudiant(String nom, String prenom, Date dateNaissance, String email) {
super();
this.nom = nom;
this.prenom = prenom;
this.dateNaissance = dateNaissance;
this.email = email;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public Date getDateNaissance() {
return dateNaissance;
}
public void setDateNaissance(Date dateNaissance) {
this.dateNaissance = dateNaissance;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Etudiant.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 20, 2016 7:42:26 AM by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="dao.Etudiant" table="etudiant">
<id name="idEtudiant">
<column name="ID_ETUDIANT" />
<generator class="native" />
</id>
<property name="nom" column="NOM" />
<property name="prenom" >
<column name="PRENOM" />
</property>
<property name="dateNaissance" >
<column name="DATE_NAISSANCE" />
</property>
<property name="email" >
<column name="EMAIL" />
</property>
</class>
Hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class"> com.mysql.jdbc.Driver</property>
<property
name="connection.url">jdbc:mysql://localhost:3306/etudes</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">100</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop the existing tables and create new one -->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.enable_lazy_load_no_trans" >
true
</property>
<!-- Mention here all the model classes along with their package name -->
<mapping resource="dao/Etudiant.hbm.xml"/>
</session-factory>
Etudiantmetierimpl.java:
#Override
public Etudiant chercheEtudiantID(Long idEtudiant) {
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
System.out.println("avant load session");
Etudiant et=session.load (Etudiant.class, idEtudiant);
//Etudiant et=session.get (Etudiant.class, idEtudiant); // presque meme chose que load
System.out.println("apres load session et ");
session.close();
return et;
}
find it finally. I change this line :
Etudiant et=session.load (Etudiant.class, idEtudiant)
to :
Etudiant et=session.get (Etudiant.class, idEtudiant)
doc:
session.load()
• It will always return a “proxy” (Hibernate term) without hitting the database. In Hibernate, proxy is an object with the given identifier value, its properties are not initialized yet, it just look like a temporary fake object.
• If no row found , it will throws an ObjectNotFoundException.
session.get()
• It always hit the database and return the real object, an object that represent the database row, not proxy.
• If no row found , it return null.

Struts2 visitor validation not work for JPA entity on EJB Module

I am using the JPA entities as models for my web layer. I am including the EJB module as a dependency for my web project on pom.xml.
I have implemented an action called CreateUserAction which implements ModelDriven:
package actions.accounts;
import com.google.inject.Inject;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import facade.UserFacadeLocal;
import java.util.logging.Level;
import java.util.logging.Logger;
import models.User;
/**
*
* #author sergio
*/
public class CreateUserAction extends ActionSupport implements ModelDriven<User>{
#Inject
private UserFacadeLocal userFacade;
private User user = new User();
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String execute() throws Exception {
Logger.getLogger(SignupAction.class.getName()).log(Level.INFO, "Registrando usuario");
userFacade.create(user);
addActionMessage("Usuario registrado con éxito");
return SUCCESS;
}
#Override
public User getModel() {
return user;
}
}
user is an instance of the class models.User from EJB module:
package models;
import java.io.Serializable;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
#Entity(name = "USERS")
#NamedQueries({
#NamedQuery(name = "User.all", query = "SELECT u FROM USERS u"),
#NamedQuery(name = "User.find", query = "SELECT u FROM USERS u WHERE u.userName = :username")
})
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name = "USER_NAME")
private String userName;
#Column(name = "PASSWD", length = 32,columnDefinition = "VARCHAR(32)")
private String password;
private String name;
private String lastname;
#Temporal(javax.persistence.TemporalType.DATE)
private Date birthday;
private String email;
private Integer mobile;
#ManyToMany(cascade={CascadeType.ALL})
#JoinTable(
name="USER_GROUPS",
joinColumns={ #JoinColumn(name="USER_NAME") },
inverseJoinColumns={ #JoinColumn(name="GROUP_NAME") }
)
private Set<Group> groups;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = hashPassword(password);
}
public Set<Group> getGroups() {
return groups;
}
public void setGroups(Set<Group> groups) {
this.groups = groups;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getMobile() {
return mobile;
}
public void setMobile(Integer mobile) {
this.mobile = mobile;
}
public String getFullname(){
return name + " " + lastname;
}
#Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final User other = (User) obj;
if ((this.userName == null) ? (other.userName != null) :
!this.userName.equals(other.userName)) {
return false;
}
return true;
}
#Override
public int hashCode() {
int hash = 3;
hash = 83 * hash + (this.userName != null ? this.userName.hashCode() : 0);
return hash;
}
private String hashPassword(String password) {
String encoded = null;
try {
ByteBuffer passwdBuffer =
Charset.defaultCharset().encode(CharBuffer.wrap(password));
byte[] passwdBytes = passwdBuffer.array();
MessageDigest mdEnc = MessageDigest.getInstance("MD5");
mdEnc.update(passwdBytes, 0, password.length());
encoded = new BigInteger(1, mdEnc.digest()).toString(16);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
return encoded;
}
}
I want to use struts2 validation by the following configuration:
CreateUserAction-validation.xml into src/main/resources/actions/accounts
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<validator type="visitor">
<param name="fieldName">user</param>
<param name="appendPrefix">false</param>
<message />
</validator>
</validators>
User-validation.xml into src/main/resources/models
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="userName">
<field-validator type="required">
<message>You must enter a value for name.</message>
</field-validator>
</field>
<field name="name">
<field-validator type="required">
<message>You must enter a value for name.</message>
</field-validator>
</field>
</validators>
the User file is well placed?
and to finalize the action settings:
<action name="signup" class="actions.accounts.SignupAction">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result>/WEB-INF/views/accounts/signup.jsp</result>
</action>
<action name="create" class="actions.accounts.CreateUserAction">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result name="input" type="redirectAction">signup</result>
<result type="redirectAction">signup</result>
</action>
thanks in advance

Resources