h:outputLabel not showing anything - java

The problem that I am facing is that after I click on the h:commandLink button the h:outputLabel isn't showing anything. I have used selectedUser to store the value when the form is submitted but it seems selectedUser is not storing any value.
1)Here is the xhtml file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head></h:head>
<h:body class="thrColElsHdr">
<div class="friends">
<h4>Friends</h4>
<h:form>
<p:selectOneMenu value="#{chatBean.selectedUser}">
<f:selectItems value="#{chatBean.friendList}" var="users" itemLabel="#{users.firstName}" itemValue="#{users}"/>
</p:selectOneMenu>
<h:commandLink>Chat</h:commandLink>
</h:form>
<br>
</br>
<h:outputLabel value="#{chatBean.selectedUser.firstName}"/>
</div>
</h:body>
</html>
2)Here is the chatBean and it is session scoped using facesconfig.xml
package com.bean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.servlet.http.HttpSession;
import com.entity.Friend;
import com.entity.User;
public class ChatBean {
private EntityManager em;
private User selectedUser;
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
public ChatBean(){
selectedUser= new User();
EntityManagerFactory emf=Persistence.createEntityManagerFactory("FreeBird");
em =emf.createEntityManager();
}
public List<User> getFriendList(){
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
User user=(User) session.getAttribute("userdet");
Query query = em.createQuery("SELECT f FROM Friend f WHERE f.email='"+user.getEmail()+"' AND f.status=1",Friend.class);
List<Friend> results =query.getResultList();
ArrayList<User> friends = new ArrayList<User>();
Iterator<Friend> it = results.iterator();
while(it.hasNext()){
System.out.println("in getFriendList...");
User friend =em.find(User.class,it.next().getFriendEmail());
friends.add(friend);
}
return friends;
}
}
3) Here is the user entity class
package com.entity;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the user database table.
*
*/
#Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private String email;
#Lob()
private String aboutMe;
private String birthDate;
private String city;
private String college;
private String confirmation;
private String contactNo;
private String country;
private String degree;
private String firstName;
private String gender;
private String highSchool;
private String image;
private String interest;
private String lastName;
private String password;
private int pincode;
#Lob()
private String quote;
private String relationship;
private String secondarySchool;
private String state;
private String street;
private String university;
private String userName;
public User() {
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAboutMe() {
return this.aboutMe;
}
public void setAboutMe(String aboutMe) {
this.aboutMe = aboutMe;
}
public String getBirthDate() {
return this.birthDate;
}
public void setBirthDate(String birthDate) {
this.birthDate = birthDate;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCollege() {
return this.college;
}
public void setCollege(String college) {
this.college = college;
}
public String getConfirmation() {
return this.confirmation;
}
public void setConfirmation(String confirmation) {
this.confirmation = confirmation;
}
public String getContactNo() {
return this.contactNo;
}
public void setContactNo(String contactNo) {
this.contactNo = contactNo;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public String getDegree() {
return this.degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getGender() {
return this.gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getHighSchool() {
return this.highSchool;
}
public void setHighSchool(String highSchool) {
this.highSchool = highSchool;
}
public String getImage() {
return this.image;
}
public void setImage(String image) {
this.image = image;
}
public String getInterest() {
return this.interest;
}
public void setInterest(String interest) {
this.interest = interest;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public int getPincode() {
return this.pincode;
}
public void setPincode(int pincode) {
this.pincode = pincode;
}
public String getQuote() {
return this.quote;
}
public void setQuote(String quote) {
this.quote = quote;
}
public String getRelationship() {
return this.relationship;
}
public void setRelationship(String relationship) {
this.relationship = relationship;
}
public String getSecondarySchool() {
return this.secondarySchool;
}
public void setSecondarySchool(String secondarySchool) {
this.secondarySchool = secondarySchool;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getStreet() {
return this.street;
}
public void setStreet(String street) {
this.street = street;
}
public String getUniversity() {
return this.university;
}
public void setUniversity(String university) {
this.university = university;
}
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}

Your managed bean must have the corresponding annotations:
#ViewScoped
#ManagedBean
public class ChatBean {
//...
}
The example can be corrected using one of these tips:
Add an action to your <h:commandLink> and bind it to a method that returns the name of your page. In this way, the page will be refreshed and it will show the new value in #{chatBean.selectedUser.firstName}:
<h:commandLink action="#{chatBean.refresh}" value="Chat" />
In your class:
public String refresh() {
return "index";
}
Add ajax behavior to your <h:commandLink> in order to update the <h:outputLabel>. You should add an id attribute to your <h:outputLabel>:
<h:commandLink value="Chat">
<f:ajax render=":theLabel" />
</h:commandLink>
<!-- jsf code -->
<h:outputLabel id="theLabel" value="#{chatBean.selectedUser.firstName}"/>

Related

How do i override functions in a Vaadin 12 project? ValueProvider, SelectionListener and ComponentEventListener

This will be quite a bit of code as I don't know what will be important. I was trying to recreated the basic UI Alejandro made in my tutorial session with him a few months ago, substituting a table in my database for the one he used. The errors I'm getting all seem related to overriding Vaadin Flow functions. I know that replaces the behavior of the Super method. IntelliJ opens the relevant Super method when I click on the errors, which I'm assuming it wants me to edit to solve the problem, but I have no idea how to do that.
I was going to paste a link to the code but the forum told me to just place it here.
Customer.java
package com.dbproject.storeui;
import java.time.LocalDate;
public class Customer {
private Long id;
private String lastname;
private String firstname;
private String email;
private String password;
private String phone;
private String street;
private String city;
private String st;
private int zip;
private LocalDate dob;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getSt() {
return st;
}
public void setSt(String st) {
this.st = st;
}
public int getZip() {
return zip;
}
public void setZip(int zip) {
this.zip = zip;
}
public LocalDate getDob() {
return dob;
}
public void setDob(LocalDate dob) {
this.dob = dob;
}
}
CustomerRepository.java
package com.dbproject.storeui;
import org.apache.ibatis.annotations.*;
import java.util.List;
#Mapper
public interface CustomerMapper {
#Select("SELECT * FROM customer ORDER BY id")
List<Customer> findAll();
#Update("UPDATE customer" +
"SET lastname=#{lastname}, firstname=#{firstname}, email=#{email}, password=#{password}, phone=#{phone}, street=#{street}, city=#{city}, st=${st}, zip=#{zip}, dob=#{dob}" +
"WHERE id=#{id}")
void update(Customer customer);
#Insert("INSERT INTO customer(lastname, firstname, email, password, phone, street, city, st, zip, dob) VALUES(#{lastname}, #{firstname}, #{email}, #{password}, #{phone}, #{street}, #{city}, #{st}, #{zip}, #{dob})")
#Options(useGeneratedKeys = true, keyProperty = "id")
void create(Customer customer);
}
CustomerView.java (the UI class)
package com.dbproject.storeui;
import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
#Route("")
public class CustomerView extends Composite<VerticalLayout> {
private final CustomerMapper customerMapper;
private Grid<Customer> grid = new Grid<>();
private TextField lastname = new TextField("Last Name");
private TextField firstname = new TextField("First Name");
private Button save = new Button("Save", VaadinIcon.CHECK.create());
private Button create = new Button("New", VaadinIcon.PLUS.create());
private VerticalLayout form = new VerticalLayout(lastname, firstname, save);
private Binder<Customer> binder = new Binder<>(Customer.class);
private Customer customer;
public CustomerView(CustomerMapper customerMapper) {
this.customerMapper = customerMapper;
grid.addColumn(Customer::getLastname).setHeader("Last Name");
grid.addColumn(Customer::getFirstname).setHeader("First Name");
grid.addSelectionListener(event -> setCustomer(grid.asSingleSelect().getValue()));
updateGrid();
save.addClickListener(event -> saveClicked());
create.addClickListener(event -> createClicked());
getContent().add(grid, create, form);
binder.bindInstanceFields(this);
binder.setBean(null);
}
private void createClicked() {
grid.asSingleSelect().clear();
setCustomer(new Customer());
}
private void saveClicked() {
binder.readBean(customer);
if (customer.getId() == null) {
customerMapper.create(customer);
} else {
customerMapper.update(customer);
}
updateGrid();
Notification.show("Saved!");
}
private void setCustomer(Customer customer) {
this.customer = customer;
form.setEnabled(customer != null);
binder.setBean(customer);
}
private void updateGrid() {
grid.setItems(customerMapper.findAll());
}
}

Uml class diagram for java

i am a newbie to java.I am trying to create a library system.
Which classes should be abstract? do i need more classes?
Yes you need many classes, Your classes should look like this :
class Person{
//attributes, getters and setters
}
class User extends Person{
//attributes, getters and setters
}
class Members extends Person{
}
class Librarian extends Person{
}
class Book{
//attributes, getters and setters
}
public class Person {
private String FirstName;
private String LastName;
private String Gender;
private String Contact;
private String Email;
public Person() {
}
public Person(String FirstName, String LastName, String Gender, String Contact, String Email) {
this.FirstName = FirstName;
this.LastName = LastName;
this.Gender = Gender;
this.Contact = Contact;
this.Email = Email;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String FirstName) {
this.FirstName = FirstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
this.LastName = LastName;
}
public String getGender() {
return Gender;
}
public void setGender(String Gender) {
this.Gender = Gender;
}
public String getContact() {
return Contact;
}
public void setContact(String Contact) {
this.Contact = Contact;
}
public String getEmail() {
return Email;
}
public void setEmail(String Email) {
this.Email = Email;
}
}
public class User extends Person {
private String Password;
private String Username;
boolean isEnabled;
public User() {
}
public User(String Password, String Username, boolean isEnabled) {
this.Password = Password;
this.Username = Username;
this.isEnabled = isEnabled;
}
public String getPassword() {
return Password;
}
public void setPassword(String Password) {
this.Password = Password;
}
public String getUsername() {
return Username;
}
public void setUsername(String Username) {
this.Username = Username;
}
public boolean isIsEnabled() {
return isEnabled;
}
public void setIsEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
}
public class Guest extends User {
public Guest() {
}
public Guest(String Password, String Username, boolean isEnabled) {
super(Password, Username, isEnabled);
}
public void App(){
}
}
public class Members extends User{
public Members() {
}
public Members(String Password, String Username, boolean isEnabled) {
super(Password, Username, isEnabled);
}
}
public class Libararian extends User {
public Libararian() {
}
public Libararian(String Password, String Username, boolean isEnabled) {
super(Password, Username, isEnabled);
}
}
public class Book {
private String Title;
private String Publisher;
private String Category;
public Book(String Title, String Publisher, String Category) {
this.Title = Title;
this.Publisher = Publisher;
this.Category = Category;
}
public Book() {
}
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String getPublisher() {
return Publisher;
}
public void setPublisher(String Publisher) {
this.Publisher = Publisher;
}
public String getCategory() {
return Category;
}
public void setCategory(String Category) {
this.Category = Category;
}
}

jaxb returning null vaue after unmarshal

I am trying to Unmarshall a xml and it is returning null value
XML:
<letterOutHeader>
<lettertype>
MN13
</lettertype>
<letterReqid>
9294678
</letterReqid>
<language>
en
</language>
<attentionTo></attentionTo>
<addressLine1></addressLine1>
<addressLine2></addressLine2>
<city>Case City</city>
<state>NY</state>
<zipCode>59559</zipCode>
<dateOfLetter>12/28/2016</dateOfLetter>
<respondByDate/>
<externalNum>Ac0287356894754</externalNum>
<letterOutFlexField>
<name>fieldOne </name>
<value>valueOne</value>
</letterOutFlexField>
<letterOutFlexField>
<name>fieldTwo</name>
<value>valueTwo</value>
</letterOutFlexField>
<letterOutFlexField>
<name>fieldThree</name>
<value>valueThree</value>
</letterOutFlexField>
<letterOutFlexField>
<name>fieldFour</name>
<value>valueFour</value>
</letterOutFlexField>
</letterOutHeader>
Bean:
package jaxb.Bean;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class LetterOutHeader {
String lettertype;
String letterReqid;
String language;
String attentionTo;
String addressLine1;
String addressLine2;
String city;
String state;
String zipCode;
String dateOfLetter;
String respondByDate;
String externalNum;
List<LetterOutFlexFieldBean> flexFields;
#XmlAttribute
public String getLettertype() {
return lettertype;
}
public void setLettertype(String lettertype) {
this.lettertype = lettertype;
}
#XmlAttribute
public String getLetterReqid() {
return letterReqid;
}
public void setLetterReqid(String letterReqid) {
this.letterReqid = letterReqid;
}
#XmlAttribute
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
#XmlAttribute
public String getAttentionTo() {
return attentionTo;
}
public void setAttentionTo(String attentionTo) {
this.attentionTo = attentionTo;
}
#XmlAttribute
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
#XmlAttribute
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
#XmlAttribute
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
#XmlAttribute
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
#XmlAttribute
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
#XmlAttribute
public String getDateOfLetter() {
return dateOfLetter;
}
public void setDateOfLetter(String dateOfLetter) {
this.dateOfLetter = dateOfLetter;
}
#XmlAttribute
public String getRespondByDate() {
return respondByDate;
}
public void setRespondByDate(String respondByDate) {
this.respondByDate = respondByDate;
}
#XmlAttribute
public String getExternalNum() {
return externalNum;
}
public void setExternalNum(String externalNum) {
this.externalNum = externalNum;
}
#XmlElement
public List<LetterOutFlexFieldBean> getFlexFields() {
return flexFields;
}
public void setFlexFields(List<LetterOutFlexFieldBean> flexFields) {
this.flexFields = flexFields;
}
}
UnMarshaling :
package jaxb.client;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import jaxb.Bean.LetterOutBean;
import jaxb.Bean.LetterOutHeader;
public class XmlToObject {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
File file = new File("C:/Users/sindhu/Desktop/Kranthi/jaxB/baseXML.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(LetterOutHeader.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
LetterOutHeader que= (LetterOutHeader) jaxbUnmarshaller.unmarshal(file);
System.out.println(que.getCity());
/* System.out.println("Answers:");
List<Answer> list=que.getAnswers();
for(Answer ans:list)
System.out.println(ans.getId()+" "+ans.getAnswername()+" "+ans.getPostedby());
*/
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
I have looked into the below posts in order to avoid duplicate question
JAXB unmarshal returning null values
JAXB unmarshalling returning Null
There are many mismatch between your provided XML and JAXB class.
Firstly, there are no attributes in your sample XML, but the JAXB contains #XmlAttribute.
Secondly, it is better to declare the #XmlAccessorType explicitly or otherwise it looks for only public fields and methods.
LetterOutHeader.java
package int1.d3;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="letterOutHeader")
#XmlAccessorType(XmlAccessType.FIELD)
public class LetterOutHeader {
String lettertype;
String letterReqid;
String language;
String attentionTo;
String addressLine1;
String addressLine2;
String city;
String state;
String zipCode;
String dateOfLetter;
String respondByDate;
String externalNum;
#XmlElement(name="letterOutFlexField")
List<LetterOutFlexFieldBean> flexField;
public String getLettertype() {
return lettertype;
}
public void setLettertype(String lettertype) {
this.lettertype = lettertype;
}
public String getLetterReqid() {
return letterReqid;
}
public void setLetterReqid(String letterReqid) {
this.letterReqid = letterReqid;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getAttentionTo() {
return attentionTo;
}
public void setAttentionTo(String attentionTo) {
this.attentionTo = attentionTo;
}
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getDateOfLetter() {
return dateOfLetter;
}
public void setDateOfLetter(String dateOfLetter) {
this.dateOfLetter = dateOfLetter;
}
public String getRespondByDate() {
return respondByDate;
}
public void setRespondByDate(String respondByDate) {
this.respondByDate = respondByDate;
}
public String getExternalNum() {
return externalNum;
}
public void setExternalNum(String externalNum) {
this.externalNum = externalNum;
}
public List<LetterOutFlexFieldBean> getFlexFields() {
if(flexField == null) {
flexField = new ArrayList<LetterOutFlexFieldBean>();
}
return this.flexField;
}
}

Struts2 How to get selected value from dropdownlist to other jsp page

This is register.jsp page. Here setting the countryList in dropdownlist from Action class
<s:select name="country" list="countryList" listKey="countryId" listValue="countryName" headerKey="0" headerValue="Country" label="Select a country">
Here I am getting all the list from Action;
when I submit action , I am getting key instead of value on success.jsp.
<s:property value="country"/>
Here I am getting selected key like 0,1,2 instead of country value.
My Action class
public class RegisterAction extends ActionSupport {
private List<String> communityList;
private List<Country> countryList;
private String country;
private String userName;
private String password;
private String gender;
private String about;
private String[] community;
private boolean mailingList;
public String execute() {
return SUCCESS;}
public String populate(){
communityList = new ArrayList<String>();
countryList = new ArrayList<Country>();
countryList.add(new Country(1,"India"));
countryList.add(new Country(2,"US"));
countryList.add(new Country(3,"UK"));
communityList.add("JAVA");
communityList.add(".NET");
communityList.add("SOA");
community=new String[]{"JAVA",".NET"};
mailingList = true;
return "populate";
}
public List<String> getCommunityList() {
return communityList;
}
public void setCommunityList(List<String> communityList) {
this.communityList = communityList;
}
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 = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public String[] getCommunity() {
return community;
}
public void setCommunity(String[] community) {
this.community = community;
}
public boolean isMailingList() {
return mailingList;
}
public void setMailingList(boolean mailingList) {
this.mailingList = mailingList;
}
public List<Country> getCountryList() {
return countryList;
}
public void setCountryList(List<Country> countryList) {
this.countryList = countryList;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Country.java
public class Country {
private String countryName;
private int countryId;
public Country(){}
public Country(int countryId,String countryName){
this.countryId=countryId;
this.countryName=countryName;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
}
You can get the value from the request object.
HttpServletRequest request = (HttpServletRequest)(ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST));
Country value = (Country)request.getParameter("country");
use listKey="countryName" listValue="countryName" in this way you will receive value

Neo4J Spring relateTo function cannot be resolved

Given the following class:
package com.example.model;
import java.util.Collection;
import java.util.Set;
import org.neo4j.graphdb.Direction;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;
import org.springframework.security.core.GrantedAuthority;
#NodeEntity
public class User {
private static final String SALT = "cewuiqwzie";
public static final String FRIEND = "FRIEND";
public static final String RATED = "RATED";
#Indexed
String login;
String name;
String password;
String info;
private Roles[] roles;
public User() {
}
public User(String login, String name, String password, Roles... roles) {
this.login = login;
this.name = name;
this.password = encode(password);
this.roles = roles;
}
private String encode(String password) {
return "";
// return new Md5PasswordEncoder().encodePassword(password, SALT);
}
#RelatedToVia(elementClass = Rating.class, type = RATED)
Iterable<Rating> ratings;
#RelatedTo(elementClass = Movie.class, type = RATED)
Set<Movie> favorites;
#RelatedTo(elementClass = User.class, type = FRIEND, direction = Direction.BOTH)
Set<User> friends;
public void addFriend(User friend) {
this.friends.add(friend);
}
public Rating rate(Movie movie, int stars, String comment) {
return relateTo(movie, Rating.class, RATED).rate(stars, comment);
}
public Collection<Rating> getRatings() {
return IteratorUtil.asCollection(ratings);
}
#Override
public String toString() {
return String.format("%s (%s)", name, login);
}
public String getName() {
return name;
}
public Set<User> getFriends() {
return friends;
}
public Roles[] getRole() {
return roles;
}
public String getLogin() {
return login;
}
public String getPassword() {
return password;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public void updatePassword(String old, String newPass1, String newPass2) {
if (!password.equals(encode(old)))
throw new IllegalArgumentException("Existing Password invalid");
if (!newPass1.equals(newPass2))
throw new IllegalArgumentException("New Passwords don't match");
this.password = encode(newPass1);
}
public void setName(String name) {
this.name = name;
}
public boolean isFriend(User other) {
return other != null && getFriends().contains(other);
}
public enum Roles implements GrantedAuthority {
ROLE_USER, ROLE_ADMIN;
#Override
public String getAuthority() {
return name();
}
}
}
I get a compilation exception here:
public Rating rate(Movie movie, int stars, String comment) {
return relateTo(movie, Rating.class, RATED).rate(stars, comment);
}
Following the tutorial here. Any insight as to where this function resides is appreciated.
You're trying to use the advanced mapping mode. See the reference manual for more information. You'll need to set up AspectJ support in your IDE. Methods are woven into your entity classes at compile time.

Categories

Resources