I´m new to the Spring MVC Framework and I´m having a problem. When trying to bind the Information of a form to my controller the following error occurs:
"Invalid property 'isDifferentLanguage' of bean class [de.pwc.form.FPagesCheckForm]: Bean property 'isDifferentLanguage' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?"
My aim is to prove if some checkboxes are checked. Strangely enough this code works for the second and third checkbox of my .jsp file. But for the first checkbox "Different language in the documents?" it is not working despite I have implemented getter and setter of the property.
This is a part of my .jsp File:
Different language in the documents? <form:checkbox path="isDifferentLanguage"/><br/>
Only compareNumbers <form:checkbox path="onlyCompareNumbers"/><br/>
Markup <form:checkbox path="markup"/><br/>
This is my form:
private int startPageOld;
private int endPageOld;
private int startPageNew;
private int endPageNew;
private boolean isDifferentLanguage;
private boolean onlyCompareNumbers;
private boolean markup;
// Files
private CommonsMultipartFile[] fileDatas;
public CommonsMultipartFile[] getFileDatas() {
return fileDatas;
}
public void setFileDatas(CommonsMultipartFile[] fileDatas) {
this.fileDatas = fileDatas;
}
public int getStartPageOld() {
return startPageOld;
}
public void setStartPageOld(int startPageOld) {
this.startPageOld = startPageOld;
}
public int getStartPageNew() {
return startPageNew;
}
public void setStartPageNew(int startPageNew) {
this.startPageNew = startPageNew;
}
public int getEndPageOld() {
return endPageOld;
}
public void setEndPageOld(int endPageOld) {
this.endPageOld = endPageOld;
}
public int getEndPageNew() {
return endPageNew;
}
public void setEndPageNew(int endPageNew) {
this.endPageNew = endPageNew;
}
public boolean isOnlyCompareNumbers() {
return onlyCompareNumbers;
}
public void setOnlyCompareNumbers(boolean onlyCompareNumbers) {
this.onlyCompareNumbers = onlyCompareNumbers;
}
public boolean isMarkup() {
return markup;
}
public void setMarkup(boolean markup) {
this.markup = markup;
}
public boolean isDifferentLanguage() {
return isDifferentLanguage;
}
public void setDifferentLanguage(boolean isDifferentLanguage) {
this.isDifferentLanguage = isDifferentLanguage;
}
If you need more information just tell me ! Thanks for your help!
Related
AEM sling model --Multifield Links component :
MissingElementsException: Could not inject all required fields
I am trying to create a multifield link(URL) component - EXTERNAL AND INTERNAL LINKS. See getpageURL() for understanding.
See the image below:
#Model(adaptables = Resource.class)
public class Links_Bean {
#Inject
private String pagePath;
#PostConstruct
protected void init() {
pagePath = getPageURL(pagePath);
}
public static String getPageURL(String pagePath) {
if (pagePath.isEmpty() || (pagePath.equals(null))) {
return null;
} else if (pagePath.startsWith("/content")) {
return pagePath.concat(".html");
} else if (pagePath.startsWith("http://") || pagePath.startsWith("https://") || pagePath.startsWith("www")) {
return pagePath;
}
return pagePath;
}
public String getPagePath() {
return pagePath;
}
public void setPagePath(String pagePath) {
this.pagePath = pagePath;
}
}
package com.hcl.aem.core.models;
#Model(adaptables = Resource.class)
public class MF_newMethod {
#Inject
#Named("items")
public Resource pagePathMF;
public List<Links_Bean> links = new ArrayList<Links_Bean>();
#PostConstruct
protected void init() {
if (pagePathMF != null) {
links = getPageList(links, pagePathMF);
}
}
public static List<Links_Bean> getPageList(List<Links_Bean> array, Resource resource) {
if (resource != null) {
Iterator<Resource> linkResource = resource.listChildren();
while (linkResource.hasNext()) {
Links_Bean lb = linkResource.next().adaptTo(Links_Bean.class);
array.add(lb);
}
}
return array;
}
public List<Links_Bean> getLinks() {
return links;
}
}
Please check weather you can able to get pagePath value, If that is not mandatory use #Optional annotation.
Use below link for reference
[https://sling.apache.org/documentation/bundles/models.html][1]
Thanks,
Kiran
protected String init() {
pagePath = getPageURL(pagePath);
return pagePath; //<--------------added this
}
and #optional what kiran said....
Your are missing an #Optional here:
...
#Inject
#Named("items")
#Optional //<--- THIS
public Resource pagePathMF;
...
I am trying to map two structures with JMapper but struggle with two encapsulated complex types and how to map them. I want to achive the following:
Source > Destination
Source.sourceString > Destination.destinationString
Source.SourceInternal > Destination.DestinationInternal
Source.SourceInternal.internalString2 > Destination.DestinationInternal.internalString
My classes look as follows:
public class Source {
private String sourceString;
private SourceInternal sourceInternal;
public String getSourceString() {
return sourceString;
}
public void setSourceString(final String sourceString) {
this.sourceString = sourceString;
}
public SourceInternal getSourceInternal() {
return sourceInternal;
}
public void setSourceInternal(final SourceInternal sourceInternal) {
this.sourceInternal = sourceInternal;
}
}
The internal source object
public class SourceInternal {
private String internalString1;
private String internalString2;
public String getInternalString1() {
return internalString1;
}
public void setInternalString1(final String internalString1) {
this.internalString1 = internalString1;
}
public String getInternalString2() {
return internalString2;
}
public void setInternalString2(final String internalString2) {
this.internalString2 = internalString2;
}
}
The destination the source should be mapped to
public class Destination {
private String destinationString;
private DestinationInternal destinationInternal;
public String getDestinationString() {
return destinationString;
}
public void setDestinationString(final String destinationString) {
this.destinationString = destinationString;
}
public DestinationInternal getDestinationInternal() {
return destinationInternal;
}
public void setDestinationInternal(final DestinationInternal destinationInternal) {
this.destinationInternal = destinationInternal;
}
}
The internal destination object.
public class DestinationInternal {
private String internalString;
public String getInternalString() {
return internalString;
}
public void setInternalString(final String internalString) {
this.internalString = internalString;
}
}
How would I achive the described mapping? Is it even possible with JMapper? Thanks.
I was looking into that a similar feature too. Here's how I managed it.
JMapperAPI jMapperAPI = new JMapperAPI()
.add(mappedClass(Destination.class)
.add(attribute("destinationString").value("sourceString"))
.add(attribute("destinationInternal").value("sourceInternal")))
.add(mappedClass(DestinationInternal.class).add(attribute("internalString").value("internalString1").targetClasses(SourceInternal.class)));
Basically the logic is to have a mapping for each nested class.
I'm trying to store a list in the Application class instance as a global variable in one of my Android applications. Below is my Application class code:
public class DefectsApplication extends Application{
private NormalUser normalUser;
private ArrayList<Complaint> complaintList;
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
private String testString;
public NormalUser getNormalUser() {
return normalUser;
}
public void setNormalUser(NormalUser normalUser) {
this.normalUser = normalUser;
}
public ArrayList<Complaint> getComplaintList() {
return complaintList;
}
public void setComplaintList(ArrayList<Complaint> m_complaints) {
this.complaintList = complaintList;
}
}
Below is my code which is trying to access the fields from the Application class instance:
DefectsApplication defectsApplication = ((DefectsApplication)getApplicationContext());
defectsApplication.setComplaintList(m_complaints);
defectsApplication.setTestString("urghhhhhhhhh");
ArrayList<Complaint> complaintList = defectsApplication.getComplaintList();
String s = defectsApplication.getTestString();
In the above code, m_complaints is a list of objects. When I try to store a String, it works. But for a list, it doesn't. Please, help me to resolve this issue.
Probably, a typo is taking place:
public void setComplaintList(ArrayList<Complaint> m_complaints) {
this.complaintList = complaintList;
}
You're setting this.complaintList to itself which is initially null. Try
public void setComplaintList(ArrayList<Complaint> m_complaints) {
this.complaintList = m_complaints;
}
Hi i am trying to pass a list of objects of type models.InputTimeSheetDataStore from view to application.java and i am getting No QueryString binder found for type java.util.List[models.InputTimeSheetDataStore]. Try to implement an implicit QueryStringBindable for this type error
in application.java i am passing list of object to view
InputTimeSheetDataStore ITSDS= new InputTimeSheetDataStore();
ITSDS.ConsultantName=EmployeeFilter;
ITSDS.Client=ClientFilter;
ITSDS.Project=ProjectFilter;
ITSDS.Role=EmployeeRoleFilter;
ITSDS.Task=Task;
ITSDS.TimeSheetDate=TimeSheetDate;
ITSDS.Hours=TaskHours;
ITSDS.IsBilled=IsBilled;
ITSDS.Workplace=WorkPlace;
InputTimeSheetList.add(ITSDS);
return ok(TimeSheetInput.render(Consultant.PopulateConsultant(),Client.PopulateClient(),Project.PopulateProject(ClientFilter),
Consultant.PopulateConsultantRole(),Consultant.ConsultantRoleRate(EmployeeRoleFilter),InputTimeSheetList));
in view i am passing that object back to application.java
#(EmployeeList:java.util.List[String],ClientList:java.util.List[String],
ProjectList:java.util.List[String],EmployeeRoleList: java.util.List[String],Rate:String,
CurrentPage:List[InputTimeSheetDataStore])
<form id="TimeSheetEntryForm" name="TimeSheetEntryForm" action="#{routes.Application.save("name","name","name","name","name","name","name","name","name",CurrentPage)}" method="GET">
<code.....>
here is my class file
InputTimeSheetDataStore.java
package models;
public class InputTimeSheetDataStore {
public String ConsultantName;
public String Client;
public String Project;
public String Role;
public String Task;
public String TimeSheetDate;
public String Hours;
public String IsBilled;
public String Workplace;
public String getConsultantName(){
return this.ConsultantName;
}
public String getClient(){
return this.Client;
}
public String getProject(){
return this.Project;
}
public String getRole(){
return this.Role;
}
public String getTask(){
return this.Task;
}
public String getTimeSheetDate(){
return this.TimeSheetDate;
}
public String getHours(){
return this.Hours;
}
public String getIsBilled(){
return this.IsBilled;
}
public String getWorkPlace(){
return this.Workplace;
}
}
my routes is
GET /Application/save controllers.Application.save(EmployeeFilter:String,ClientFilter:String,ProjectFilter:String, EmployeeRoleFilter:String,Task:String,TaskHours:String,TimeSheetDate:String,IsBilled:String,WorkPlace:String,CurrentPage:java.util.List[models.InputTimeSheetDataStore])
can someone help me with the implicit querybinder of type InputTimeSheetDataStore
Thanks in advance
Hi this is the example implementation of QueryStringbindable:
public class InputTimeSheetDataStore implements QueryStringBindable<InputTimeSheetDataStore> {
public String consultantName, client, project;
#Override
public Optional bind(String key, Map data) {
if (data.containsKey("consultantName")) {
this. consultantName = data.get("consultantName").toString();
}
if (data.containsKey("client")) {
this.client = data.get("client").toString();
}
if (data.containsKey("project")) {
this.project = data.get("project").toString();
}
return Optional.of(this);
}
#Override
public String unbind(String key) {
return null;
}
#Override
public String javascriptUnbind() {
return null;
}
}
Extra tips for you, when writing a programming language, make sure you are following the code convention. For example: the convention in Java syntax you must write variable with lower case for the first character;
public String ConsultantName; // this is wrong
public String consultantName; //this is right
Hope it helps.
I am not being able to make messageSource work in the Pojo classes,its throwing a nullpointerexception. However in all the other classes namely controller,service messageSource is working alright. Could someone please suggest what needs to be done ?
#Autowired
private MessageSource messageSource;
I have autowired the MessageSource using the above code snippet.
public class ProposalWiseSelectionForm implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
#Autowired
private MessageSource messageSource;
private String txtPageHierarchy="";
private String txtLineOfBusiness;
private String txtProduct;
private String btn;
private String clickedGo="N";
private List arrLineOfBusiness=new ArrayList();
private List arrProduct=new ArrayList();
#Valid
private ArrayList documentList=initiateDocumentList();
private String txtPageMode="I";
private String enableDiscardBtn="N";
private String enableInsertBtn="N";
private String isDivVisible="N";
private int numApplicationType=1;
public ProposalWiseSelectionForm() {
}
public String getTxtPageHierarchy() {
return txtPageHierarchy;
}
public void setTxtPageHierarchy(String txtPageHierarchy) {
this.txtPageHierarchy = txtPageHierarchy;
}
public String getTxtLineOfBusiness() {
return txtLineOfBusiness;
}
public void setTxtLineOfBusiness(String txtLineOfBusiness) {
this.txtLineOfBusiness = txtLineOfBusiness;
}
public String getTxtProduct() {
return txtProduct;
}
public void setTxtProduct(String txtProduct) {
this.txtProduct = txtProduct;
}
public String getBtn() {
return btn;
}
public void setBtn(String btn) {
this.btn = btn;
}
public String getClickedGo() {
return clickedGo;
}
public void setClickedGo(String clickedGo) {
this.clickedGo = clickedGo;
}
public List getArrLineOfBusiness() {
return arrLineOfBusiness;
}
public void setArrLineOfBusiness(List arrLineOfBusiness) {
this.arrLineOfBusiness = arrLineOfBusiness;
}
public List getArrProduct() {
return arrProduct;
}
public void setArrProduct(List arrProduct) {
this.arrProduct = arrProduct;
}
public void setArrProduct(ArrayList arrProduct) {
this.arrProduct = arrProduct;
}
public ArrayList getDocumentList() {
return documentList;
}
public void setDocumentList(ArrayList documentList) {
this.documentList = documentList;
}
public String getTxtPageMode() {
return txtPageMode;
}
public void setTxtPageMode(String txtPageMode) {
this.txtPageMode = txtPageMode;
}
public String getEnableDiscardBtn() {
return enableDiscardBtn;
}
public void setEnableDiscardBtn(String enableDiscardBtn) {
this.enableDiscardBtn = enableDiscardBtn;
}
public String getEnableInsertBtn() {
return enableInsertBtn;
}
public void setEnableInsertBtn(String enableInsertBtn) {
this.enableInsertBtn = enableInsertBtn;
}
public String getIsDivVisible() {
return isDivVisible;
}
public void setIsDivVisible(String isDivVisible) {
this.isDivVisible = isDivVisible;
}
public int getNumApplicationType() {
return numApplicationType;
}
public void setNumApplicationType(int numApplicationType) {
this.numApplicationType = numApplicationType;
}
}
In order to be able to use #Autowired in a class, that class has to be managed by Spring.
of
Your ProposalWiseSelectionForm class is obviously not managed by Spring and therefor messageSource is always null.
Using #Autowired MessageSource messageSource in your other classes works, because as you mention those classes are managed by Spring (as you have mentioned they are either controllers, services etc).
I am guessing that ProposalWiseSelectionForm is a DTO used to capture values from a form. The sort of class will not be a Spring bean and therefor you can't autowire stuff into it.
I suggest you either move the logic you need out of the DTO and into the controller (or some Spring managed utility) or in the extreme case that you absolutely need #Autowired in the DTO, take a look at #Configurable here and here
Try using #Component,you might be getting this issue because of the fact the Pojo class is not being recognized.
You have to make your class a Spring bean
Add #Component annotation to your class and add these 2 lines to your appContext.xml:
<context:component-scan base-package="com.<your-company-name>" />
<context:annotation-config />
Or just add the service in your beans section in the appContext.xml if you wish not to work with Spring component-scan feature.