No getter method for property - java

Hi I am trying to use struts to get a bean to my jsp code the bean I am using in my jsp page is: but whenever I run the jsp I am receiving
No getter method for property: "testData.team.type" of bean: "unitForm".
I am trying to write baseball to my JSP page.
The code for my action form is:
import com.TestGettingData;
import org.apache.struts.action.ActionForm;
public class UnitForm extends ActionForm {
private TestGettingData testData = new TestGettingData();
public TestGettingData getTestData() {
return testData;
}
public void setTestData(TestGettingData testData) {
this.testData = testData;
}
}
testing data class has:
public class TestGettingData extends Sport{
private String team = "Yankees";
private String position = "short stop";
public void setTeam(String tm) {
team = tm; }
public String getTeam() {
return team; }
public void setPosition(String po) {
position = po; }
public String getPosition() {
return position;
}
}
and finally in my sport class:
public class Sport{
public String type = "baseball";
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

Instead of testData.team.type, try testData.type. type is a property in testData not in team.
Update
${unitForm.testData.type} should display "baseball" in your JSP.

Related

Java Step Builder with Conditional Steps

I'm busy implementing Step Builders into a Java application and I've written some horrendous code. I'm quite certain I'm missing a necessary step.
For an example, I'll use the buildable class Machine.java
public class Machine {
private String type;;
private boolean mobile;
private final String mobileType;
public Machine(MachineBuilder builder) {
this.type = builder.type;
this.mobile = builder.mobile;
this.mobileType = builder.mobileType;
}
public String getType() { return this.type; }
public boolean getMobile() { return this.mobile; }
public String getMobileType() { return this.mobileType; }
}
And the step builder for it as MachineBuilder.java
public class MachineBuilder {
public String type;
public boolean mobile;
public String mobileType;
public MachineBuilder() { }
// initialize builder
public Builder start() {
return new Builder();
}
// interfaces
public interface iType {
iBuild withType(String type);
}
public interface iMobileType {
iBuild withMobileType(String mobileType);
}
public interface iBuild {
iMobileType withMobile();
iBuild withMobileType(String mobileType);
Machine build();
}
// subclass to return
public static class Builder extends MachineBuilder implements iType, iMobileType, iBuild {
public iBuild withType(String type) {
super.type = type; return this;
}
public iMobileType withMobile() {
super.mobile = true; return this;
}
public iBuild withMobileType(String mobileType) {
super.mobileType = mobileType; return this;
}
public Machine build() {
return new Machine(this);
}
}
}
The intention is to have type as a required step, then mobile as optional but if mobile is used then mobileType must be used as well.
It's only half working though
// fine
Machine car = new MachineBuilder()
.start().withType("car").withMobile().withMobileType("driving").build();
System.out.println(car.getType() + ":" + car.getMobile() + ":" + car.getMobileType());
// fine
Machine washingMachine = new MachineBuilder()
.start().withType("washingMachine").build();
System.out.println(washingMachine.getType() + ":" + washingMachine.getMobile() + ":" + washingMachine.getMobileType());
// corrupt (no type)
Machine boat = new MachineBuilder()
.start().withMobile().withMobileType("sailing").build();
System.out.println(boat.getType() + ":" + boat.getMobile() + ":" + boat.getMobileType());
// corrupt (no anything)
Machine bicycle = new MachineBuilder()
.start().build();
System.out.println(bicycle.getType() + ":" + bicycle.getMobile() + ":" + bicycle.getMobileType());
I had to initialize the builder object with the method start but this is not implementing any of the interfaces so just calling start then build will corrupt the object. Similarly calling the optional method for mobile allows it to bypass the type.
Is it possible to force flow direction from the start without using a start method at all? I feel like I am missing something very stupid.
PS. sorry for slapping so much code into the question I just wanted to illustrate the issue as best as I can
Thrill to answer this question. I try to rewrite your code. Just reorganize it following Step Builder Pattern's strategy.
Add no description here, hope you can easily understand the code.
class Machine {
private String type;
private boolean isMobile;
private String mobileType;
public static TypeStep builder(){
return new MachineBuilder();
}
public interface TypeStep{
IsMobileStep withType(String type);
}
public interface IsMobileStep{
MobileTypeStep withMobile(boolean isMobile);
}
public interface MobileTypeStep{
Build withMobileType(String mobileType);
}
public interface Build{
Machine build();
}
public static class MachineBuilder implements TypeStep, IsMobileStep, MobileTypeStep, Build {
private String type;
private boolean isMobile;
private String mobileType;
#Override
public IsMobileStep withType(String type) {
this.type = type;
return this;
}
#Override
public MobileTypeStep withMobile(boolean isMobile) {
this.isMobile = isMobile;
return this;
}
#Override
public Build withMobileType(String mobileType) {
this.mobileType = mobileType;
return this;
}
#Override
public Machine build() {
return new Machine(this);
}
}
private Machine(MachineBuilder machineBuilder) {
this.type = machineBuilder.type;
this.isMobile = machineBuilder.isMobile;
this.mobileType = machineBuilder.mobileType;
}
public String getType() {
return type;
}
public boolean isMobile() {
return isMobile;
}
public String getMobileType() {
return mobileType;
}
}
Test run:
public class Main{
public static void main(String[] args) {
Machine car = Machine.builder().withType("car").withMobile(true).withMobileType("driving").build();
System.out.println("Model 1:"+ car.getType() +":"+ car.isMobile()+":"+car.getMobileType());
Machine boat = Machine.builder().withType("boat").withMobile(true).withMobileType("driving").build();
System.out.println("Model 2:"+ boat.getType() +":"+ boat.isMobile()+":"+boat.getMobileType());
}
}
Output:
Model 1:car:true:driving
Model 2:boat:true:driving
For better readability: Github Repo Step Builder
I think your builder implementation is very difficult and not very correct.
The typical builder should have private constructors, initial methods, field setters and build methods. I would do so:
public class MachineBuilder {
public String type;
public boolean mobile;
public String mobileType;
private MachineBuilder (final String type, final boolean mobile, final String mobileType) {
this.type = type;
this.mobile = mobile;
this.mobileType = mobileType;
}
private MachineBuilder(){
}
public MachineBuilder setType(final String source) {
this.type = source;
return this;
}
public MachineBuilder setMobile(final boolean source) {
this.mobile = source;
return this;
}
public MachineBuilder setMobileType(final String source) {
this.mobileType = source;
return this;
}
public static MachineBuilder init() {
return new MachineBuilder();
}
public static MachineBuilder init(final String type, final boolean mobile, final String mobileType) {
return new MachineBuilder(type, mobile, mobileType);
}
public MachineBuilder build() {
return Machine(this.type, this.mobile, this.mobileType);
}
}

How to solve issue of "cannot cast object" for Microsoft SQL in spring boot?

I am trying to call a stored procedure for my application using Microsoft SQL. However, when I run the stored procedure to pass back the contents of the object it fails. I have the objects as AVSApplication and in that class it has a list of variables and methods. I tried using an Iterable and a List but both produce the same error. I am not sure where I went wrong. I looked at other similar StackOverflow questions but I didn't get much from it.
Error:
java.lang.ClassCastException: java.base/[Ljava.lang.Object; cannot be cast to com.Mapping.AVSApplication
at com.Mapping.Employeecontroller.getAll(Employeecontroller.java:33) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~
Java Entity Code:
import java.util.*;
import javax.persistence.*;
#Entity
#NamedStoredProcedureQueries(value= {
#NamedStoredProcedureQuery(name= "procedure-one", procedureName= "GetAllAppWithStatus")
})
public class AVSApplication implements java.io.Serializable {
private static final long serialVersionUID = 1L;
#Id
private String appcode;
private String acronym;
private String appname;
private String sys_id;
private String mapstatus;
private String sdg;
private String status;
private String statuscode;
//Constructor
public AVSApplication(String appcode, String acronym, String appname, String sys_id, String mapstatus,
String sdg, String status, String statuscode) {
super();
this.appcode = appcode;
this.acronym = acronym;
this.appname = appname;
this.sys_id = sys_id;
this.mapstatus = mapstatus;
this.sdg = sdg;
this.status = status;
this.statuscode = statuscode;
}
//Getters
public String getAppcode() {
return appcode;
}
public String getAcronym() {
return acronym;
}
public String getAppname() {
return appname;
}
public String getSys_id() {
return sys_id;
}
public String getMapstatus() {
return mapstatus;
}
public String getSdg() {
return sdg;
}
public String getStatus() {
return status;
}
public String getStatuscode() {
return statuscode;
}
//Setters
public void setAppcode(String appcode) {
this.appcode = appcode;
}
public void setAcronym(String acronym) {
this.acronym = acronym;
}
public void setAppname(String appname) {
this.appname = appname;
}
public void setSys_id(String sys_id) {
this.sys_id = sys_id;
}
public void setMapstatus(String mapstatus) {
this.mapstatus = mapstatus;
}
public void setSdg(String sdg) {
this.sdg = sdg;
}
public void setStatus(String status) {
this.status = status;
}
public void setStatuscode(String statuscode) {
this.statuscode = statuscode;
}
}
DAO:
#Repository
public class Employeedao {
#Autowired
private EntityManager em;
/**
* Method to fetch all employees from the db.
* #return
*/
#SuppressWarnings("unchecked")
public List<AVSApplication> getAllEmployees() {
return em.createNamedStoredProcedureQuery("procedure-one").getResultList();
}
}
Controller:
#RestController
public class Employeecontroller {
#Autowired
Employeedao edao;
/**
* Method to fetch all employees from the db.
* #return
*/
#RequestMapping(value= "/getall")
public void getAll() {
System.out.println("All objects: " + edao.getAllEmployees());
System.out.println("Get the first item in list: " + edao.getAllEmployees().get(0).getAppcode());
}
}
In given code there is nothing that would map rows returned by stored procedure AVSApplication instances:
#NamedStoredProcedureQueries(value= {
#NamedStoredProcedureQuery(name= "procedure-one", procedureName= "GetAllAppWithStatus")
})
If stored procedure matches nicely to entity, then definining result class can be enough:
#NamedStoredProcedureQueries(value= {
#NamedStoredProcedureQuery(
name= "procedure-one",
procedureName= "GetAllAppWithStatus",
resultClasses = {AVSApplication.class}
})
If there is some discrepancies, one must define SqlResultSetMapping and refer to it from resultsetMappings.

Access to class attributes' values using Java Annotations

I am working with a java example using annotations, I created a simple POJO (java bean) using annotations to its attributes. I want to have the ability to create new objects of this type and retrieve the values of its attributes using the annotations created.
My POJO :
import java.io.Serializable;
import annotations.BusinessObject;
import annotations.BusinessObjectAttribute;
import annotations.BusinessObjectName;
import annotations.BusinessObjectPolicy;
import annotations.BusinessObjectRevision;
import annotations.BusinessObjectVault;
#BusinessObject
public class IndusTask implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
// Mandatory to create new object !
#BusinessObjectName
private String taskName;
#BusinessObjectRevision
private String taskRevision;
#BusinessObjectVault
private String vault;
// Mandatory to invoke iTask.create(context, policy) in Database
#BusinessObjectPolicy
private String policy;
//Specific attributes
#BusinessObjectAttribute
private String taskDescription;
#BusinessObjectAttribute
private String creationDate;
#BusinessObjectAttribute
private Integer weight;
public IndusTask() {
}
public IndusTask(String taskName, String taskRevision, String vault, String policy, String taskDescription,
String creationDate, Integer weight) {
super();
this.taskName = taskName;
this.taskRevision = taskRevision;
this.vault = vault;
this.policy = policy;
this.taskDescription = taskDescription;
this.creationDate = creationDate;
this.weight = weight;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public String getTaskRevision() {
return taskRevision;
}
public void setTaskRevision(String taskRevision) {
this.taskRevision = taskRevision;
}
public String getVault() {
return vault;
}
public void setVault(String vault) {
this.vault = vault;
}
public String getTaskDescription() {
return taskDescription;
}
public void setTaskDescription(String taskDescription) {
this.taskDescription = taskDescription;
}
public String getCreationDate() {
return this.creationDate;
}
public void setCreationDate(String creationDate) {
this.creationDate = creationDate;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public String getPolicy() {
return policy;
}
public void setPolicy(String policy) {
this.policy = policy;
}
}
Example of attributes' declaration:
*Business Object Type declaration
package annotations;
import java.lang.annotation.*;
//#Target(ElementType.TYPE)
#Retention(RetentionPolicy.RUNTIME)
public #interface BusinessObject {
}
*Business Object Name Attribute:
package annotations;
import java.lang.annotation.*;
//#Target(ElementType.FIELD)
#Retention(RetentionPolicy.RUNTIME)
public #interface BusinessObjectName {
}
I Created a main to test if all the annotations are detected:
public class MainImpl {
public static void main(String[] args) {
// TODO Auto-generated method stub
IndusTask myTask = new IndusTask("mytstTask", "001", "eService Production", "TstTask Process",
"myTstTask Description", "2018/02/16#15:30:10:GMT", 200);
System.out.println(myTask.getClass().getAnnotations().length);
}
}
Output is displaying 1 ! so only the first annotation is detected !
I was told also that the object attributes values can be accessed using these annotation (something similar to) :
object.getClass().getAnnotations()
How can i do ?
You need to iterate through the fields, get their annotations and set the value wherever the annotation matches (it can match multiple fields):
#Retention(RetentionPolicy.RUNTIME)
public #interface Field1 {}
#Retention(RetentionPolicy.RUNTIME)
public #interface Field2 {}
public static class UnderTest {
#Field1
private String field1;
#Field2
private int field2;
public UnderTest(String field1, int field2) {
this.field1 = field1;
this.field2 = field2;
}
#Override
public String toString() {
return field1 + "=" + field2;
}
}
public static void setter(Object obj, Class<? extends Annotation> fieldAnnotation, Object fieldValue) throws IllegalAccessException {
for (Field field: obj.getClass().getDeclaredFields()) {
for (Annotation annot: field.getDeclaredAnnotations()) {
if (annot.annotationType().isAssignableFrom(fieldAnnotation)) {
if (!field.isAccessible()) {
field.setAccessible(true);
}
field.set(obj, fieldValue);
}
}
}
}
public static void main(String[] argv) throws IllegalAccessException {
UnderTest underTest = new UnderTest("A", 1);
System.out.println(underTest);
setter(underTest, Field1.class, "B");
setter(underTest, Field2.class, 2);
System.out.println(underTest);
}
Running this prints
A=1
B=2
Sounds like you're after the annotations on the fields too?
E.g. for the first private field:
myTask.getClass().getDeclaredFields()[0].getAnnotations()
Note depending how you're accessing a private field, you will sometimes also need to first ensure it is accessible:
...getDeclaredFields()[0].setAccessible(true);
[edit]
The values are reachable too from the fields. A basic worked example:
for (Field f : myTask.getClass().getDeclaredFields()) {
f.setAccessible(true);
System.out.println(f.getName() + "=" + f.get(myTask));
System.out.println(" annotations=" + java.util.Arrays.toString(f.getAnnotations()));
}

updating a record in a db - JSF JPA etc

i am wondering if you could help me
basically i have created a db, and it adds data to two pieces of data to the table, leaving the rest of the columns blank, what i want to do, is be able to update these records with some more data for the blank columns, how can i achieve this ?
this is my code atm, but i just get a null point error and don't know if im doing it right
This is the u.i.
<p>
Student Number : <!--More for me than anything -->
<h:inputText value="#{editMarkingBean.markSectionTwo.studentNumber}" />
</p>
this is where the student number is entered, this is what i want to update, the record that contains this student number (no way can there be more than one of the same username )
<p:spinner id="ajaxspinner80-100" value="#{editMarkingBean.markSectionTwo.markSectionTwo}"
stepFactor="1" min="80" max="100" disabled="#{formBean.number != 8}">
<p:ajax update="ajaxspinnervalue" process="#this" />
</p:spinner>
this is the value i want to add to the column markSectionTwo
the save button
<p:commandButton action="#{editMarkingBean.markSectionTwo}" value="#{bundle.buttonSave}" update=":growl" icon="ui-icon-disk"/>
the backing bean :
private MarkingService markingService;
#Inject
private MarkingFacade markingFacade;
public void markSectionTwo() {
this.markingFacade.edit(this.markSectionTwo);
this.setMessage("Mark Saved");
}
and this is the entity for the table creation
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String studentNumber,markingStage, markingCompleted, markSectionOne, markSectionTwo, markSectionThree, markSectionFour, markSectionFive, overalMark, plagorism, feedback, comments;
i get the error
WARNING: javax.el.PropertyNotFoundException: /lecturer/marking/marking-section-two.xhtml #109,82 value="#{editMarkingBean.markSectionTwo.markSectionTwo}": Target Unreachable, 'null' returned null
how can i update the records based on the student number ?
Thanks guys
EDIT
here is the complete editMarkingController class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sws.control;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import sws.business.MarkingService;
import sws.entities.Marking;
import sws.persistance.MarkingFacade;
/**
*
* #author Richard
*/
#Named(value = "editMarkingBean")
#ViewScoped
public class EditMarkingController {
private String searchString;
private String ordering;
private String criteria;
private String match;
private Date today;
private String caseMatch;
private int spinnerField;
private Marking markSectionOne;
private Marking studentNumber;
private Marking markSectionTwo;
private MarkingService markingService;
#Inject
private MarkingFacade markingFacade;
/*
public String markSectionOne() {
//supposing the data in markSectionOne is filled...
this.markingFacade.create(markSectionOne);
this.setMessage("Mark Saved");
//after saving...
markSectionOne = new Marking();
// now navigating to the next page
return "/lecturer/marking/marking-section-two";
}
*/
public void editMark() {
this.markingFacade.edit(this.markSectionTwo);
this.setMessage("Mark Saved");
}
public void markSectionTwo() {
this.markingFacade.edit(this.markSectionTwo);
this.setMessage("Mark Saved");
}
private void setMessage(String message) {
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(message, ""));
}
public Marking getMarkSectionTwo() {
return markSectionTwo;
}
public void setMarkSectionTwo(Marking markSectionTwo) {
this.markSectionTwo = markSectionTwo;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getOrdering() {
return ordering;
}
public void setOrdering(String ordering) {
this.ordering = ordering;
}
public String getCriteria() {
return criteria;
}
public void setCriteria(String criteria) {
this.criteria = criteria;
}
public String getMatch() {
return match;
}
public void setMatch(String match) {
this.match = match;
}
public Date getToday() {
return today;
}
public void setToday(Date today) {
this.today = today;
}
public String getCaseMatch() {
return caseMatch;
}
public void setCaseMatch(String caseMatch) {
this.caseMatch = caseMatch;
}
public int getSpinnerField() {
return spinnerField;
}
public void setSpinnerField(int spinnerField) {
this.spinnerField = spinnerField;
}
public Marking getMarkSectionOne() {
return markSectionOne;
}
public void setMarkSectionOne(Marking markSectionOne) {
this.markSectionOne = markSectionOne;
}
public Marking getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(Marking studentNumber) {
this.studentNumber = studentNumber;
}
public MarkingService getMarkingService() {
return markingService;
}
public void setMarkingService(MarkingService markingService) {
this.markingService = markingService;
}
public MarkingFacade getMarkingFacade() {
return markingFacade;
}
public void setMarkingFacade(MarkingFacade markingFacade) {
this.markingFacade = markingFacade;
}
}
the complete marking service
import java.util.List;
import javax.ejb.EJB;
import javax.inject.Inject;
import sws.entities.Marking;
import sws.entities.ProjectIdea;
import sws.persistance.MarkingFacade;
import sws.persistance.PersonFacade;
/**
*
* #author Richard
*/
public class MarkingService {
#EJB
private MarkingFacade markingFacade;
public List<Marking> getAllMarks() {
return markingFacade.findAll();
}
}
and comeplte marking entity
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sws.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
*
* #author Richard
*/
#Entity(name = "MARKING")
public class Marking implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String studentNumber,markingStage, markingCompleted, markSectionOne, markSectionTwo, markSectionThree, markSectionFour, markSectionFive, overalMark, plagorism, feedback, comments;
public String getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
public String getMarkingStage() {
return markingStage;
}
public void setMarkingStage(String markingStage) {
this.markingStage = markingStage;
}
public String getMarkingCompleted() {
return markingCompleted;
}
public void setMarkingCompleted(String markingCompleted) {
this.markingCompleted = markingCompleted;
}
public String getMarkSectionOne() {
return markSectionOne;
}
public void setMarkSectionOne(String markSectionOne) {
this.markSectionOne = markSectionOne;
}
public String getMarkSectionTwo() {
return markSectionTwo;
}
public void setMarkSectionTwo(String markSectionTwo) {
this.markSectionTwo = markSectionTwo;
}
public String getMarkSectionThree() {
return markSectionThree;
}
public void setMarkSectionThree(String markSectionThree) {
this.markSectionThree = markSectionThree;
}
public String getMarkSectionFour() {
return markSectionFour;
}
public void setMarkSectionFour(String markSectionFour) {
this.markSectionFour = markSectionFour;
}
public String getMarkSectionFive() {
return markSectionFive;
}
public void setMarkSectionFive(String markSectionFive) {
this.markSectionFive = markSectionFive;
}
public String getOveralMark() {
return overalMark;
}
public void setOveralMark(String overalMark) {
this.overalMark = overalMark;
}
public String getPlagorism() {
return plagorism;
}
public void setPlagorism(String plagorism) {
this.plagorism = plagorism;
}
public String getFeedback() {
return feedback;
}
public void setFeedback(String feedback) {
this.feedback = feedback;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Marking)) {
return false;
}
Marking other = (Marking) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "sws.entities.Marking[ id=" + id + " ]";
}
public void setmarkSectionOne(String markSectionOne) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
EDIT 2:
i have added a postconstruct
#PostConstruct
public void markSectionTwo() {
this.markingFacade.edit(this.markSectionTwo);
markSectionTwo = new Marking();
this.setMessage("Mark Saved");
}
but now i get the error message http 500 error
javax.servlet.ServletException: WELD-000049 Unable to invoke public void sws.control.EditMarkingController.markSectionTwo() on sws.control.EditMarkingController#44de1491
root cause
org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke public void sws.control.EditMarkingController.markSectionTwo() on sws.control.EditMarkingController#44de1491
root cause
java.lang.reflect.InvocationTargetException
root cause
javax.ejb.EJBException
root cause
java.lang.IllegalArgumentException: Object: null is not a known entity type.
when i try to load the page
EDIT 3
i have fixed that issue, but now i am only able to add the record, what i am trying to do is merge the records, so if the studentNumber is the same as already in the table then update the markSectionTwo to this value rather than creating a new row in the db for it
private Marking markSectionTwo;
private MarkingService markingService;
#Inject
private MarkingFacade markingFacade;
#PostConstruct
public void init() {
this.markSectionTwo = new Marking();
}
public String markSectionTwo() {
//supposing the data in markSectionOne is filled...
//markSectionOne.setMarkSectionOne("markSectionOne");
//markSectionTwo.setMarkSectionTwo("markSectionTwo");
this.markingFacade.edit(markSectionTwo);
this.setMessage("Mark Saved");
//after saving...
markSectionTwo = new Marking();
this.setMessage("Mark Saved");
// now navigating to the next page
return "/lecturer/marking/marking-section-two";
}
private void setMessage(String message) {
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(message, ""));
}
your error message
javax.el.PropertyNotFoundException (...) #{editMarkingBean.markSectionTwo.markSectionTwo}"
basically says that you must have
a managed bean called editMarkingBean
an object in your managed bean called markSectionTwo with proper getter and setter
an attribute in your object markSectionTwo called markSectionTwo with proper getter and setter
so what EL is trying to call is
editMarkingBean.getMarkSectionTwo().getMarkSectionTwo()
please check all your classes and, if possible, post all the relevant parts in your question, such as classes names (all of them), managed bean scope annotations, getters and setters and attributes.

XStream, CircularReferenceException

Please consider this code. Is it using Circular Reference? If not why am I getting CircularReferenceException, while enabling NO_REFERENCE mode in XStream. Anyone, please clarify the thing.
#XStreamAlias("BalanceEnquiry")
public class BalanceEnquiry extends EAIRequest {
#XStreamImplicit
private List<BalanceEnquiry.Detail> details;
public List<Detail> getDetails() {
....
}
public void setDetails(Detail... details) {
....
}
#XStreamAlias("details")
public final class Detail {
#XStreamAsAttribute
private String item;
private BalanceEnquiry.Detail.Request request;
public String getItem() {
....
}
public void setItem(String item) {
....
}
public Request getRequest() {
....
}
public void setRequest(Request request) {
....
}
public final class Request {
private String code;
private String branch;
public String getCode() {
....
}
public void setCode(String code) {
....
}
public String getBranch() {
....
}
public void setBranch(String branch) {
....
}
}
}
}
I suspect it's because Detail is an inner class. As such, it has an implicit reference to the instance of the outer class (and hence forms a circular reference). See here for more details.

Categories