How to edit a content assist behavior in eclipse - java

Is there a way to edit the content behavior or is there a plugin that does the following ... ?
I have a JSF project
the content assistant completes phrases only for attributes that has getters/setters methods
#ManagedBean(name = "myBean")
#ViewScoped
public class ViewScopedBean {
String name;
String age;
public ViewScopedBean() {
}
public String method() {
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
using ctrl+space in <h:commandButton value="action listener" actionListener="#{myBean.<ctrl+space>}" /> shows only methods and name attribute, is there away to make it also show the age attribute ?

Related

Vaadin BeanFieldGroup - "Property is not cascaded" when binding nested property

I've been searching for hours on here and on the Vaadin forums, but I seem to have a unique problem here.
I simplified my problem a lot to be able to illustrate it easily.
So I have a Bean class:
public class Bean {
private String name;
private NestedBean nestedBean;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public NestedBean getNestedBean() {
return nestedBean;
}
public void setNestedBean(NestedBean nestedBean) {
this.nestedBean = nestedBean;
}
Bean() {
this.name = "Bean";
this.nestedBean = new NestedBean();
}
}
And its nested field, class NestedBean:
public class NestedBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
NestedBean() {
this.name = "NestedBean";
}
}
So now I want to bind an instance of Bean to two TextFields, with the help of a BeanFieldGroup:
Bean bean = new Bean();
BeanFieldGroup<Bean> binder = new BeanFieldGroup<>(Bean.class);
binder.setItemDataSource(bean);
addComponent(binder.buildAndBind("Name", "name"));
addComponent(binder.buildAndBind("Nested name", "nestedBean.name"));
This, however, throws this exception:
java.lang.IllegalArgumentException: Property com.reygok.vaadin.main.Bean.nestedBean is not cascaded
Caused by: org.apache.bval.jsr.UnknownPropertyException: Property com.reygok.vaadin.main.Bean.nestedBean is not cascaded
I tried different solutions, like:
Creating the TextFields first and then using
binder.bind(textField, "nestedBean.name");
Doing this first:
binder.getItemDataSource().addNestedProperty("nestedBean.name");
But nothing changed the Exception. So does someone know what causes this?
Thanks a lot in advance!
I found it, so if others have the same problem:
The solution is to add the #Valid annotation to the fields that have nested fields inside of them.
So in my example:
public class Bean {
private String name;
#Valid
private NestedBean nestedBean;
...
I recommand you to bind member before setting bean data source
BeanFieldGroup<Bean> binder = new BeanFieldGroup<>(Bean.class);
// first
addComponent(binder.buildAndBind("Name", "name"));
addComponent(binder.buildAndBind("Nested name", "nestedBean.name"));
// then
binder.setItemDataSource(bean);

How to map single JSON field to multiple JAVA field with GSON?

I'm trying to parse JSON using Retrofit and Gson, but I need to map one JSONfield
's value to multiple JAVA fields inside bean class.
Here is an example code:
class A{
#SerializedName("name");
private String name;
#SerializedName("name");
private String fullName;
}
This is the error I'm seeing: class A declares multiple JSON fields named name. Is there any way to do this?
Update: Please avoid suggesting removing one field from the bean or making changes into getter and setter. The project is huge, and the field is being used later in many other cases, so I don't want to mess with the structure. The question is pretty much clear and on the point.
No need to declare JSON for fullname use name value with fullname in setter gatter.
class A{
#SerializedName("name");
private String name;
private String fullName;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFullName() {
return name;
}
public void setFullName(String fullName) {
this.name = fullName;
}
}

Spring NotBlank annotation with errorCode parameter

I have the following form:
public class Form {
#NotBlank(errorCode = "my.custom.error")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
My goal is to reject value with specified error code.
But unfortunately, I cannot do it.
The field rejected with my message wrapped by Form name.
Will be good to know in which way error code for the similar annotation can be specified?

Audit fields of a class using a class level annotation (aspectj)

I'm writing a simple auditing framework with aspectj, which allows me to audit the fields of a class which are annotated with an #Audit annotation.
As value the #Audit annotation expects an array of field names to be watched
Example Usage:
#Audit({"name","phoneNumber"})
class User {
private String name;
private String phoneNumber;
public getName(){
return name;
};
public setName(String name){
this.name=name;
}
}
How does the Aspect look that watches the assignment of fields that are annotated like in the above example?
Here the stub of my first try:
#Retention(RetentionPolicy.RUNTIME)
#Target({ElementType.TYPE})
public #interface Audit {
String[] value()
}
#Aspect
class AuditAspect {
#Pointcut("????")
public void markedFieldWasModified(){}
#AfterReturning("markedFieldWasModified()")
public void addFieldToModifiedFields(JoinPoint jp, AuditableEO eo){
eo.addModifiedField(jp.getSignature().getName());
}
// inter Type declarations
public interface IAuditableEO {
public Iterator<String> modifiedFields();
public boolean modified();
public boolean addModifiedField(String field);
};
}
according to https://eclipse.org/aspectj/doc/next/quick5.pdf
you should be able to do set(* *.*) && #target(Audit)
you then have to check the joinpoint if an auditable field is being modified.
How about not over-engineering the whole thing and directly annotating fields instead of classes? You can also skip the IAuditableEO interface IMO, I cannot see why it would be useful. Here is a simple example similar to yours, just with the aspect in code-style syntax (I prefer it to annotation-style syntax for clarity, but you can easily convert it by yourself):
Audit annotation for fields (not classes):
package de.scrum_master.app;
import java.lang.annotation.*;
#Retention(RetentionPolicy.RUNTIME)
#Target({ElementType.FIELD})
public #interface Audit {}
User class with a sample main method:
package de.scrum_master.app;
public class User {
private int id;
#Audit private String name;
#Audit private String phoneNumber;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getPhoneNumber() { return phoneNumber; }
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
public static void main(String[] args) {
User user = new User();
user.setId(11);
user.setName("John Doe");
user.setPhoneNumber("+49-1111-23456789");
System.out.println("User(" + user.getId() + ", " + user.getName() + ", " + user.getPhoneNumber() + ")");
}
}
Audit aspect:
package de.scrum_master.aspect;
import de.scrum_master.app.Audit;
public aspect AuditAspect {
pointcut fieldModification() : set(#Audit * *);
after() : fieldModification() {
System.out.println(thisJoinPointStaticPart);
}
}
Sample output:
set(String de.scrum_master.app.User.name)
set(String de.scrum_master.app.User.phoneNumber)
User(11, John Doe, +49-1111-23456789)
As you can see, only the annotated fields are caught, not the ID field. This permits for fine-granular auditing on a per-field basis. Furthermore in the advide you have everything you need if you want to record anything in and audit database: field type and name, class name and so forth.

Cannot load/save properties of the ViewModel's property

I have problem accessing the property of an object inside my ViewModel. I got unreached destination error. Any pointers please? Thanks.
Error Message:
Target Unreachable, 'toto' returned null
Basically, I will get the error when I fill in the textbox and click somewhere in the window. When I use other ViewModel's property (which is a String), it works as I expected.
Setup:
I use JBoss Studio. The app is running on JBoss AS 7. Basically I follow this guide http://books.zkoss.org/wiki/ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_Maven to create my project.
Zul file:
<window apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('com.maylab.fault.TicketsViewModel')"
title="Trouble Ticket" width="600px" border="normal">
<hbox style="margin-top:20px">
<textbox value="#save(vm.toto.name)"></textbox>
<label value="#load(vm.toto.name)"></label>
</hbox>
</window>
ViewModel:
package com.maylab.fault;
import org.zkoss.bind.annotation.*;
import com.maylab.fault.Person;
public class TicketsViewModel {
private String ticket;
private String test;
private Person toto;
public Person getToto() {
return toto;
}
public void setToto(Person toto) {
this.toto = toto;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public String getTicket() {
return ticket;
}
public void setTicket(String ticket) {
this.ticket = ticket;
}
}
Person class:
package com.maylab.fault;
public class Person {
private String name;
public Person(){
}
public Person(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
If you will check your viewmodel, you have wrote this code private Person toto; and with get/set method now as you know toto=null so to resolve this issue you have to change your code like this
private Person toto = new Person();
this will resolve your issue.

Categories

Resources