I have a form made with fxml, it has like 20 fields. (I.e. Person) and I have my controller with the 20 fields (one for every field) o want to know if there is a way to box all these fields in a unique bean like PersonBean. Actually I have to set all the fields to the bean manually in the initialize method.
Something like in the Id of the fxml input put something like "person.name".
Not 100% sure but try something like:
text="${controller.person.name}"
where person is a property of the controller and name is a property of PersonBean.
See:
http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#expression_binding
Binding a Label's text property (in an FXML file) to an IntegerProperty (in a controller)
You might need to provide JavaFX properties such as
ObjectProperty<PersonBean> personProperty();
StringProperty nameProperty();
but maybe there is also some support for plain JavaBeans properties.
Related
In my Spring MVC / Thymeleaf application I apply an UUID when instantiating a brand new instance of any model entity (I do it in an AbstractModel that each entity extends). I use it then for custom equals method implementation that spreads along all entities
#Column(name = "UUID", nullable = false, unique = true)
private String uuid = IdGenerator.createId();
I some other place I create a form bean (simple wrapper) containing a graph of such newly created entities.
an example wrapper would look like this:
WrapperObj obj = new Obj(new FooEntity(), new BarEntity())
both FooEntity and BarEntity have some fileds like ints, Strings etc. that are initially not set. The only fileld that is set isthe UUID
Then I pass the wrapper to the form where I eventually fill up the empty fields.
When I submit the form and the entities are not modified, they still exist in the wrapper. When I attach another object the the wrapper WrapperObj obj = new Obj(new FooEntity(), new BarEntity(), new TestObj()) that has no UUID initially set and submit the form without changing it's fields, the TestObj is reset to null.
This is my desired behaviour for the other UUID-enabled entities.
How can I instruct the spring mvc framework to ignore the UUID field at the binding time so that the entities also become null when not modified?
Thanks for your help!
CORRECTION
the TestObj object was not bound to any input field in the form.
UPDATE
I have just discovered that it is not the uuid that causes the problem. I my wrapper I have another child entity, let's say BoolFoo that has only boolean fields (apart of the id(int) and uuid(string) set by the AbstractEntity class).
Those fields are of type checkbox within the form.
When I submit the form without modifying any of BoolFoo's fileds, BoolFoo as a whole is set to null (although the id and uuid are present when passing the object to the form).
However, if there is at least one text field(did not checked against other types) provided for any child entity, the child object (or any actually) will never be null when comming back from the form.
I've tried already the binder.setDisallowedFields("uuid") approach as well as binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); but no matter what I do, the unmodified objects will not be set to null.
Looks like there are different rules when it comes to different form field types in spring mvc.
Has anyone come across similar problem?
The DataBinder has two properties named allowedFields and disallowedFields that you could define what to bind or not. Just use that with annotation #InitBinder before executing controller method:
#InitBinder
public void initBinder(WebDataBinder binder) {
binder.setDisallowedFields("uuid");
}
I have created a little XPage search form with a backing bean. This works great with strings, everything is bound using Expression Language and I can access the value in my bean to compose the actual search string.
However, this doesn't seem to be working for dates. I have a date field that looks like this:
<xp:inputText
themeId="Field.Date"
id="inputStartDate" value="#{Search.calStart}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
My bean has a very basic getter/setter for this:
public Date getCalStart() {
return calStart;
}
public void setCalStart(Date calStart) {
this.calStart = calStart;
}
The problem is that while the field will populate from the backing bean, the bean is not affected by the field. So if in my constructor I set a date field to 7/18/2014, it looks fine on my page. But if I pick a date on the page and perform a refresh, the value does not change in the bean. The dates remain null or whatever I've initialized them to in the bean.
Is there something about the converter (other than handling it as a Java Date in my bean, which I'm doing) that breaks the value binding?
I have had this problem with Date and Beans before but not in Xpages.
What I did was to circumvent the getter/setter with my own and within those convert to the format I want.
So I have a simple MVC set of files:
- ObjectBuilder.java
- Object.java
- objectForm.jsp
- ObjectController.java
I have a dropdown list in objectForm.jsp, that I've populated with the correct ArrayList items (examples: messageTemplate, secondTemplate).
When I choose a template in the dropdown, my controller can gather that chosen template behind-the-scenes using:
this.ObjectBuilder.getTemplate(object.getTemplate())
which takes in the chosen template and using ObjectBuilder (#Service "ObjectBuilder"), populates the template from a .properties file.
My question then is: I can display the chosen template name from the list (ex. messageTemplate) but I can't figure out how to display the .properties populated template for that chosen name. Any ideas on how to go about doing this?
Use <context:property-placeholder location="classpath:test.properties" /> to load the properties file, than I will suggest to do something like this:
#Value("${yourkey}")
private String templateValue;
#ModelAttribute("template")
public String getTemplate(){
return templateValue;
}
and now you can get the value in request scope. use jstl or expression language to access it on jsp.
I've a little issue to propose.
I've defined in Spring a bean named EnvParam. I've passed this bean in my report processed by Jasper, using an hashmap of parameters.
In Jasper XML I've mapped my bean with import tag in this way:
<import value="Mypath.EnvParam" />
After that I want to point my bean properties in GUI elements.
So, I've defined in Jasper some variables in this way:
varDummy = $P{EnvParam}.myProperty
so in my GUI element I've that link $V{varDummy}.
When I run my application my report doesn't show the correct value of property, setting NULL in my GUI.
But if I put in my GUI object my property $P{EnvParam}.myProperty without using of variable the value will show correctly.
I've resolved my issue, changing the procession time of variable, put the value as "REPORT"
The default the value has set on "NOW" (I think - in italian, version used the value named "ADESSO")
I am working on a project which made use of an old (but nice) framework Struts 1.3, and I am trying to accomplish a simple task.
I have a bean containing a property, which is a key corresponding to a property file. I would like to use it for recall the appropriate translation.
Variable in property file
props.myprop.sample=This is my sample property
The property is in a bean passed to the jsp called for convenience AllProps which has a getter for the property, and this should be a pseudo code:
<bean:define id="sample" name="AllProps" property="sample" type="java.lang.String"/> // should result in sample = props.myprop.sample
<div><bean:message key="sample"/></div>
Which should output:
<div>This is my sample property</div>
But obviously result in a property not found, can you give me help on how to deal with this ?
I would like to stick as much as possible to Struts tag, then Jsp tag, and scriptlet as last resource.
Thanks
Straight from the documentation:
<bean:message>
Render an internationalized message string to the response.
Retrieves an internationalized message for the specified locale, using
the specified message key, and write it to the output stream. Up to
five parametric replacements (such as "{0}") may be specified.
The message key may be specified directly, using the key attribute, or
indirectly, using the name and property attributes to obtain it from a
bean.
(emphasis mine)
So, all you need is
<bean:message name="AllProps" property="sample"/>