I want to generate follpwing xml format
<order_history>
<order store_id="SSO">
<attribute name="store_label">SSO Store</attribute>
<attribute name="order_id">7039012</attribute>
<attribute name="status">Shipped</attribute>
<attribute name="total">11.76</attribute>
<attribute name="description"/>
<attribute name="tracking_num"/>
<attribute name="lineItemCount">ssolineItemCount</attribute>
<attribute name="tracking_href"/>
<attribute name="submitted_date">11/19/2015</attribute>
<attribute name="sort_date">1448316686906</attribute>
<attribute name="detail_url">http://shop.scholastic.com/webapp/wcs/stores/servlet/MyAcctItemHistoryView?langId=-1&storeId=10751&orderId=7039011</attribute>
</order>
<order_history>
With the following mapping class:
order.java
#XmlRootElement
public class Order {
#XmlAttribute(name="store_id")
private String store_id="SSO";
#XmlAttribute
private String store_label;
#XmlAttribute
private int order_id;
#XmlAttribute
private String status;
#XmlAttribute
private double total;
#XmlAttribute
private String description;
#XmlAttribute
private int tracking_num;
#XmlAttribute
private String lineItemCount;
#XmlAttribute
private String tracking_href;
#XmlAttribute
private String submitted_date;
#XmlAttribute
private int sort_date;
#XmlAttribute
private String detail_url;
public String getStore_label() {
return store_label;
}
public void setStore_label(String store_label) {
this.store_label = store_label;
}
public int getOrder_id() {
return order_id;
}
public void setOrder_id(int order_id) {
this.order_id = order_id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getTracking_num() {
return tracking_num;
}
public void setTracking_num(int tracking_num) {
this.tracking_num = tracking_num;
}
public String getLineItemCount() {
return lineItemCount;
}
public void setLineItemCount(String lineItemCount) {
this.lineItemCount = lineItemCount;
}
public String getTracking_href() {
return tracking_href;
}
public void setTracking_href(String tracking_href) {
this.tracking_href = tracking_href;
}
public String getSubmitted_date() {
return submitted_date;
}
public void setSubmitted_date(String submitted_date) {
this.submitted_date = submitted_date;
}
public int getSort_date() {
return sort_date;
}
public void setSort_date(int sort_date) {
this.sort_date = sort_date;
}
public String getDetail_url() {
return detail_url;
}
public void setDetail_url(String detail_url) {
this.detail_url = detail_url;
}
OrderHistort.java
#XmlRootElement
public class OrderHistory {
List<Order> orders = new ArrayList<Order>();
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
With these two classes ia m able to generate following xml:
<order_history>
<order store_id="SSO">
<store_label>SSO Store</store_label>
<order_id>7039012</order_id>
<status>Shipped</status>
<total>11.76</total>
<description>desc</description>
<tracking_num>12234</tracking_num>
<lineItemCount>ssolineItemCount</lineItemCount>
<tracking_href"/>wwww.abc.com</tracking_href>
<submitted_date>11/19/2015</submitted_date>
<sort_date>1448316686906</sort_date>
<detail_url>http://shop.scholastic.com/webapp/wcs/stores/servlet/MyAcctItemHistoryView?langId=-1&storeId=10751&orderId=7039011</detail_url>
</order>
</order_history>
Can anybody help me out in getting desired format with
Thanks
My Order.java class
#XmlAttribute(name="store_id")
private String store_id="SSO";
private String store_label;
private int order_id;
private String status;
private double total;
private String description;
private int tracking_num;
private String lineItemCount;
private String tracking_href;
private String submitted_date;
private int sort_date;
private String detail_url;
public String getStore_label() {
return store_label;
}
public void setStore_label(String store_label) {
this.store_label = store_label;
}
public int getOrder_id() {
return order_id;
}
public void setOrder_id(int order_id) {
this.order_id = order_id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getTracking_num() {
return tracking_num;
}
public void setTracking_num(int tracking_num) {
this.tracking_num = tracking_num;
}
public String getLineItemCount() {
return lineItemCount;
}
public void setLineItemCount(String lineItemCount) {
this.lineItemCount = lineItemCount;
}
public String getTracking_href() {
return tracking_href;
}
public void setTracking_href(String tracking_href) {
this.tracking_href = tracking_href;
}
public String getSubmitted_date() {
return submitted_date;
}
public void setSubmitted_date(String submitted_date) {
this.submitted_date = submitted_date;
}
public int getSort_date() {
return sort_date;
}
public void setSort_date(int sort_date) {
this.sort_date = sort_date;
}
public String getDetail_url() {
return detail_url;
}
public void setDetail_url(String detail_url) {
this.detail_url = detail_url;
}
Related
I have a requirement where I need to plan inside subset of data. For example, I have a stock of steel beams of certain grade. While planning I need to fit the available beams into stock only if they match the profile.
How do I do this with constraint streams. Any example would be appreciated.
I don't seem to get the hang around constraint streams.
I need to fit the ProjectMembers into StockMembers only if the profile matches.
Planning entity
#PlanningEntity
public class ProjectMember
extends AbstractPersistable
implements Labeled {
private int requiredLength; // in mm
private String profile;
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
private StockMember stockMember;
ProjectMember() {
}
public ProjectMember(long id, int requiredLength) {
super(id);
this.requiredLength = requiredLength;
}
public int getRequiredLength() {
return requiredLength;
}
public void setRequiredLength(int requiredLength) {
this.requiredLength = requiredLength;
}
#PlanningVariable
public StockMember getStockMember() {
return stockMember;
}
public void setStockMember(StockMember stockMember) {
this.stockMember = stockMember;
}
#Override
public String getLabel() {
return "Project Member " + id;
}
}
public class StockMember
extends AbstractPersistable
implements Labeled {
private int length; // in mm
private String profile;
private int cost; // in dollars
StockMember() {
}
public StockMember(long id, int length, int cost) {
super(id);
this.length = length;
this.cost = cost;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
public void setProfile(String profile) {
this.profile = profile;
}
public String getProfile() {
return this.profile;
}
#Override
#JsonIgnore
public String getLabel() {
return "Stock Member " + id;
}
}
Planning solution
#PlanningSolution
public class NestMembers extends AbstractPersistable {
private List<StockMember> stockMemberList;
private List<ProjectMember> projectMemberList;
private HardSoftScore score;
NestMembers() {
}
public NestMembers(long id, List<StockMember> stockMemberList,
List<ProjectMember> projectMemberList) {
super(id);
this.stockMemberList = stockMemberList;
this.projectMemberList = projectMemberList;
}
#ValueRangeProvider
#ProblemFactCollectionProperty
public List<StockMember> getStockMemberList() {
return stockMemberList;
}
public void setStockMemberList(List<StockMember> computerList) {
this.stockMemberList = computerList;
}
#PlanningEntityCollectionProperty
public List<ProjectMember> getProjectMemberList() {
return projectMemberList;
}
public void setProjectMemberList(List<ProjectMember> projectMemberList)
{
this.projectMemberList = projectMemberList;
}
#PlanningScore
public HardSoftScore getScore() {
return score;
}
public void setScore(HardSoftScore score) {
this.score = score;
}
Constraint Provider
public class NestingConstraintProvider implements ConstraintProvider {
#Override
public Constraint[] defineConstraints(ConstraintFactory
constraintFactory) {
return new Constraint[]{
matchProfile(constraintFactory),
requiredLengthTotal(constraintFactory),
memberCost(constraintFactory)
};
}
Constraint requiredLengthTotal(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(ProjectMember.class)
.groupBy(ProjectMember::getStockMember,
sum(ProjectMember::getRequiredLength))
.filter((stockMember, requiredLength) -> requiredLength >
stockMember.getLength())
.penalize(HardSoftScore.ONE_HARD,
(stockMember, requiredLength) -> requiredLength -
stockMember.getLength())
.asConstraint("requiredLength");
}
Constraint matchProfile(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(ProjectMember.class)
.join(StockMember.class).
filter((projectMember, stockMember) ->
!projectMember.getProfile().equals(stockMember.getProfile()))
.penalize(HardSoftScore.ONE_HARD)
.asConstraint("requiredProfileMatch");
}
//
Constraint memberCost(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(StockMember.class)
.ifExists(ProjectMember.class, equal(Function.identity(),
ProjectMember::getStockMember))
.penalize(HardSoftScore.ONE_SOFT, StockMember::getCost)
.asConstraint("cost");
}
I am doing a REST API with Java Resteasy framework (using Jackson as well).
I was trying to define 2 api endpoints almost equal:
#POST
#Path("/addbook")
#Produces(MediaType.APPLICATION_XML)
#Consumes(MediaType.APPLICATION_XML)
public BookAdvanced addBook (BookAdvanced book){...}
#POST
#Path("/addbook")
#Produces(MediaType.APPLICATION_XML)
#Consumes(MediaType.APPLICATION_XML)
public Book addBook (Book book){...}
Is this possible? What I want is, depending on the xml arriving execute one or the other method
Here book class:
package package1;
import javax.xml.bind.annotation.*;
import java.util.Date;
#XmlRootElement(name = "book")
public class Book {
private Long id;
private String name;
private String author;
#XmlAttribute
public void setId(Long id) {
this.id = id;
}
#XmlElement(name = "title")
public void setName(String name) {
this.name = name;
}
#XmlElement(name = "author")
public void setAuthor(String author) {
this.author = author;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
// constructor, getters and setters
}
Here BookAdvanced class:
package package1;
import javax.xml.bind.annotation.*;
import java.util.Date;
#XmlRootElement(name = "book")
public class BookAdvanced {
private Long id;
private String name;
private String author;
private int year;
#XmlAttribute
public void setId(Long id) {
this.id = id;
}
#XmlElement(name = "title")
public void setName(String name) {
this.name = name;
}
#XmlElement(name = "author")
public void setAuthor(String author) {
this.author = author;
}
#XmlElement(name = "year")
public void setYear(int year) {
this.year = year;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public int getYear() {
return year;
}
// constructor, getters and setters
}
27-Jan-2023 12:33:18.238 WARN [http-nio-8080-exec-39] org.jboss.resteasy.core.registry.SegmentNode.match RESTEASY002142: Multiple resource methods match request "POST /hello/addbook". Selecting one. Matching methods: [public package1.BookAdvanced prova_gradle_war.HelloWorldResource.addBook(package1.BookAdvanced), public package1.Book prova_gradle_war.HelloWorldResource.addBook(package1.Book)]
Matching is based on the request URI and not the request body. There is no real way to match the path and decide the method to use based on the body.
You could do something manually where you inspect the data and determine which type to create.
Student Model--
Which code I must write to set photo type in the Student?
package mh.st.model;
import java.sql.Date;
import java.time.LocalDate;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.image.Image;
public class Student {
private IntegerProperty id;
private StringProperty firstName;
private StringProperty lastName;
private StringProperty fatherName;
private IntegerProperty ID;
private StringProperty phone;
private StringProperty birthday;
private ObjectProperty<Image>photo;
public Student()
{
}
public Student(int id,String firstName,String lastName,String fatherName,int ID,String phone,String birthday,Object photo)
{
this.id=new SimpleIntegerProperty(id);
this.firstName=new SimpleStringProperty(firstName);
this.lastName=new SimpleStringProperty(lastName);
this.fatherName=new SimpleStringProperty(fatherName);
this.ID=new SimpleIntegerProperty(ID);
this.phone=new SimpleStringProperty(phone);
this.birthday=new SimpleStringProperty(birthday);
}
public IntegerProperty getId() {
return id;
}
public StringProperty getFatherName() {
return fatherName;
}
public void setFatherName(String fatherName) {
this.fatherName =new SimpleStringProperty(fatherName);
}
public StringProperty getFirstName() {
return firstName;
}
public StringProperty getLastName() {
return lastName;
}
public IntegerProperty getID() {
return ID;
}
public StringProperty getPhone() {
return phone;
}
public StringProperty getBirthday() {
return birthday;
}
public void setFirstName(String firstName) {
this.firstName =new SimpleStringProperty(firstName);
}
public void setLastName(String lastName) {
this.lastName =new SimpleStringProperty(lastName);
}
public void setID(Integer ID) {
this.ID =new SimpleIntegerProperty(ID);
}
public void setPhone(String phone) {
this.phone =new SimpleStringProperty(phone);
}
public void setBirthday(String birthday) {
this.birthday =new SimpleStringProperty(birthday);
}
}
Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type)
Am integrating room into my existing project. While annotating a POJO, which implements Parcelable, with #Entity tag and making necessary changes, am getting this error. I already have an empty constructor in it. Any help would be appreciated.
#Entity(tableName = "Departments")
public class Department implements Parcelable {
#PrimaryKey(autoGenerate = true)
private Integer primaryId;
private Integer id;
private String departmentName;
private String logoUrl;
#Embedded
private ArrayList<Template> templateList;
public Department() {
}
protected Department(Parcel in) {
this.primaryId = (Integer) in.readSerializable();
this.departmentName = in.readString();
this.logoUrl = in.readString();
this.id = (Integer) in.readSerializable();
this.templateList = in.createTypedArrayList(Template.CREATOR);
}
public static final Creator<Department> CREATOR = new Creator<Department>() {
#Override
public Department createFromParcel(Parcel in) {
return new Department(in);
}
#Override
public Department[] newArray(int size) {
return new Department[size];
}
};
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(primaryId);
dest.writeString(departmentName);
dest.writeString(logoUrl);
dest.writeSerializable(id);
dest.writeTypedList(templateList);
}
public Integer getPrimaryId() {
return primaryId;
}
public void setPrimaryId(Integer primaryId) {
this.primaryId = primaryId;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public ArrayList<Template> getTemplateList() {
return templateList;
}
public void setTemplateList(ArrayList<Template> templateList) {
this.templateList = templateList;
}
}
#Entity(tableName = "Templates")
public class Template implements Parcelable {
#PrimaryKey(autoGenerate = true)
private Integer primaryId;
private Integer id;
private String code;
private String description;
private Integer departmentId;
#Embedded
private ArrayList<Issue> issueList;
public Template() {
}
private Template(Parcel in) {
this.primaryId = (Integer) in.readSerializable();
this.code = in.readString();
this.description = in.readString();
this.id = (Integer) in.readSerializable();
this.departmentId = (Integer) in.readSerializable();
this.issueList = in.createTypedArrayList(Issue.CREATOR);
}
public static final Creator<Template> CREATOR = new Creator<Template>() {
#Override
public Template createFromParcel(Parcel in) {
return new Template(in);
}
#Override
public Template[] newArray(int size) {
return new Template[size];
}
};
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(primaryId);
dest.writeString(code);
dest.writeString(description);
dest.writeSerializable(id);
dest.writeSerializable(departmentId);
dest.writeTypedList(issueList);
}
public Integer getPrimaryId() {
return primaryId;
}
public void setPrimaryId(Integer primaryId) {
this.primaryId = primaryId;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ArrayList<Issue> getIssueList() {
return issueList;
}
public void setIssueList(ArrayList<Issue> issueList) {
this.issueList = issueList;
}
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
}
#Entity(tableName = "Issues")
public class Issue implements Parcelable {
#PrimaryKey(autoGenerate = true)
private Integer primaryId;
private Integer id;
private String code;
private String description;
private Integer parentIssue;
public Issue() {
}
protected Issue(Parcel in) {
this.primaryId = (Integer) in.readSerializable();
this.code = in.readString();
this.description = in.readString();
this.id = (Integer) in.readSerializable();
this.parentIssue = (Integer) in.readSerializable();
}
public static final Creator<Issue> CREATOR = new Creator<Issue>() {
#Override
public Issue createFromParcel(Parcel in) {
return new Issue(in);
}
#Override
public Issue[] newArray(int size) {
return new Issue[size];
}
};
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(primaryId);
dest.writeString(code);
dest.writeString(description);
dest.writeSerializable(id);
dest.writeSerializable(parentIssue);
}
public Integer getPrimaryId() {
return primaryId;
}
public void setPrimaryId(Integer primaryId) {
this.primaryId = primaryId;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getParentIssue() {
return parentIssue;
}
public void setParentIssue(Integer parentIssue) {
this.parentIssue = parentIssue;
}
}
Room assumes your entity class will be having only one constructor. But there is no such limitations, If you have multiple constructor then annotate one of them with
#Ignore
Room will ignore this constructor and compile without any error.
Example
#Entity(tableName = "Departments")
public class Department implements Parcelable {
#PrimaryKey(autoGenerate = true)
private Integer primaryId;
private Integer id;
private String departmentName;
private String logoUrl;
#Embedded
private ArrayList<Template> templateList;
/**Room will ignore this constructor
**/
#Ignore
public Department() {
}
protected Department(Parcel in) {
this.primaryId = (Integer) in.readSerializable();
this.departmentName = in.readString();
this.logoUrl = in.readString();
this.id = (Integer) in.readSerializable();
this.templateList = in.createTypedArrayList(Template.CREATOR);
}
}
I'm not sure why you are getting your specific constructor error. That said your code will error from embedding the ArrayList. #Embedded is not meant to be used this way. #Embedded allows you to flatten your POJO structure when storing it. Nested POJO properties will appear as if they had been properties on the parent POJO. Using Embedded on a List is the same as asking it to flatten the properties of the ArrayList object and store them, not flatten the list items and store them.
The appropriate measure is to transition into a foreign key, primary key relationship. An alternative solution is to create a new POJO that contains your list of items (ie Templates, with an 's'). This would contain an ArrayList of Template objects. You would then define a converter that converts the POJO to a json/comma seperated list, and stores it in a single column that by default would be called "templates". Here is a link to this approach :
Android room persistent library - TypeConverter error of error: Cannot figure out how to save field to database"
Hope this helps.
Hi I want to display the bean value inside the text box using struts2 , But its not working ,Please help.
Even I tried to set and get the value from the bean but still not working.
I have attached the output .
Customer.java
package com.java.bean;
public class Customer {
private int id;
private String customerName;
private String cifNumber;
private int idNumber;
private String idCountry;
private String idType;
private int master_id;
private String rmCode;
private String customerCountry;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCifNumber() {
return cifNumber;
}
public void setCifNumber(String cifNumber) {
this.cifNumber = cifNumber;
}
public int getIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public String getIdCountry() {
return idCountry;
}
public void setIdCountry(String idCountry) {
this.idCountry = idCountry;
}
public String getIdType() {
return idType;
}
public void setIdType(String idType) {
this.idType = idType;
}
public int getMaster_id() {
return master_id;
}
public void setMaster_id(int master_id) {
this.master_id = master_id;
}
public String getRmCode() {
return rmCode;
}
public void setRmCode(String rmCode) {
this.rmCode = rmCode;
}
public String getCustomerCountry() {
return customerCountry;
}
public void setCustomerCountry(String customerCountry) {
this.customerCountry = customerCountry;
}
}
CustomerSearchActionForam.java
package com.vaannila;
public class CustomerSearchActionForm extends org.apache.struts.action.ActionForm{
private int id;
private String customerName;
private String cifNumber;
private int idNumber;
private String idCountry;
private String idType;
private int master_id;
private String rmCode;
private String customerCountry;
private String message;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCifNumber() {
return cifNumber;
}
public void setCifNumber(String cifNumber) {
this.cifNumber = cifNumber;
}
public int getIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public String getIdCountry() {
return idCountry;
}
public void setIdCountry(String idCountry) {
this.idCountry = idCountry;
}
public String getIdType() {
return idType;
}
public void setIdType(String idType) {
this.idType = idType;
}
public int getMaster_id() {
return master_id;
}
public void setMaster_id(int master_id) {
this.master_id = master_id;
}
public String getRmCode() {
return rmCode;
}
public void setRmCode(String rmCode) {
this.rmCode = rmCode;
}
public String getCustomerCountry() {
return customerCountry;
}
public void setCustomerCountry(String customerCountry) {
this.customerCountry = customerCountry;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
SearchCustomer.java
import javax.servlet.http.HttpServletRequest;
import java.beans.*;
import java.util.List;
import java.util.Iterator;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.util.MessageResources;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.java.bean.Customer;
import com.java.bean.LoginUser;
public class SearchCustomer extends org.apache.struts.action.Action {
#Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustomerSearchActionForm customerSearch = (CustomerSearchActionForm) form;
MessageResources msgResource = getResources(request);
String cifNumber_=customerSearch.getCifNumber();
String Result_ = "success";
System.out.println("CIF NUMBER:"+cifNumber_);
SearchCustomer Scust = new SearchCustomer();
List customer=Scust.listCustomers(cifNumber_);
request.setAttribute("customerList",customer);
Iterator iterator = customer.iterator();
if(iterator.hasNext()){
System.out.println("customer found");
customerSearch.setMessage(msgResource.getMessage("msg.customerfound"));
}
else{
System.out.print("Customer Not Found");
customerSearch.setMessage(msgResource.getMessage("error.nocustomerfound"));
}
System.out.println("List of Customers : "+customer);
return mapping.findForward(Result_);
}
public List listCustomers(String cifNumber_){
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = null;
List customer = null;
try{
tx = session.beginTransaction();
Query sql = session.createQuery("from Customer where cifNumber=:cifNumbervalue");
System.out.println("Query printing "+sql);
sql.setParameter("cifNumbervalue",cifNumber_);
customer = sql.list();
System.out.println("CUSTOMER LIST ITERATION"+customer);
for (Iterator iterator = customer.iterator(); iterator.hasNext();){
Customer cust = (Customer) iterator.next();
String cifNumber=cust.getCifNumber();
String custName=cust.getCustomerName();
System.out.println("----------------------------------------------------------- - -------------------------------------------");
System.out.print("CifNumber: " + cifNumber+" CustomerName :"+custName);
}
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
return customer;
}
}
LoginHome.jsp (to display my records from database)
<%#page contentType="text/html"%>
<%#page pageEncoding="UTF-8"%>
<%#taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<div style="color:red">
<html:errors />
</div>
<html:form action="/Login" >
User Name :<html:text name="LoginActionForm" property="userName" />
Password :<html:password name="LoginActionForm" property="passWord" />
<html:submit value="Login" />
</html:form>
</body>
OUTPUT
CifNumber: 10000
CustomerName: JP Morgon
IDNumber: 123321
ID Country: SINGAPORE
RM CODE: E001
CustomerCountry: USA
Customer Details
CIF NUMBER :
CUSTOMER NAME :
ID NUMBER :
ID COUNTRY :
RM CODE :
CUSTOMER COUNTRY :
login