How to remove OK and Cancel button on VM Jaxb to make user more easier to input value and move to next field using just single tab. I want to use VM Jaxb as DTO to transfer data between user and object. So user will not access to object directly.
Create an action that lets all the properties be updated in a single go:
public VM update(String code, String firstName, String lastName) { ... }
UPDATE:
The action can be invoked with an inline prompt by associating it with one of the properties using #MemberOrder or .layout.xml
#MemberOrder(named="lastName", sequence="1")
public VM update(String code, String firstName, String lastName) { ... }
Related
Is it possible to use API instead of following sql query for user authentication in openfire properties:
jdbcAuthProvider.passwordSQL: SELECT username FROM
chat_authentication WHERE username=?
Basically, the chat_authentication table in our mysql database is not functioning properly and hence some users' entries are not there in the table. So I want to hit the API(which has very low failure rate) directly. How can I do that in this case?
You have to create your own class to substitute DefaultAuthProvider.class of Openfire.
Can looks like:
import org.jivesoftware.openfire.auth.AuthProvider
public class MyAuthProvider implements AuthProvider
and implements correctly all the methods.
As alternative you can extends OF's DefaultAuthProvider and override all the methods
public void authenticate(String username, String password) throws UnauthorizedException
public void authenticate(String username, String token, String digest) throws UnauthorizedException
getPassword(String)
public boolean checkPassword(String username, String testPassword) throws UserNotFoundException
public void setPassword(String username, String password).
Finally, make a jar of your class, deploy it in openfireDirectory/lib and change the value of property
provider.auth.className
with your MyAuthProvider fullname.
You can do it
by Admin Console Panel -> Server -> System Property
or by database updating OfProperty table.
After that, you'll must shut down and start Openfire.
In our project (springMVC) Rest API project I wish to only use ONE model for both request and response (to avoid having to add tons of code to copy field from object to object)
I'd like to use Swagger to handle all the doc, but I'm running into a little problem. For example let say I have a model User
public class User {
private Long id;
private String username;
private String password;
}
And a simple controller
public void createUser(#RequestBody User user)...
public User getUser(Long id) ..
Now I would like swagger to hide the property password on deserialization but not serialization (so having it display for the Input but the output)
and the opposite for the Id field.
I have tried using #JsonIgnore coupled with #JsonProperty but on the swagager-ui it either displays everything or hides everything. I cannot manage to it work.
Could someone indicate me what is the best way of archiving my goal ? Is it possible to use a single model for request and response while using swagger? In case it is not possible to use #JsonIgnore, is there a way to archive this differently ?
Swagger doesn't want you to have different input/output models with the same name. You should simply create an interface and attach that to the input, and for the output extend that interface or add an implementation with the additional field. For example, please see here for modeling tips:
https://swaggerhub.com/api/swagger-tutorials/modeling-samples/1.0.0
Your exact use case is one of them. The solution posted in the above link is here:
definitions:
User:
description: this is a user that would be passed into the system
properties:
username:
type: string
UserResponse:
allOf:
- $ref: '#/definitions/User'
- type: object
required:
- id
properties:
id:
type: string
format: uuid
readOnly: true
where User is the input object, and UserResponse is the output object, with the additional id field.
Add #JsonIgnore with getter of the field and #JsonProperty with the setter or with the field . As Due to use of immutable code or final fields sometime setter doesn't work.
example :
public class Student {
private Float name;
private String rollnum;
private String section;
#JsonProperty
private Boolean passOrFailed;
#JsonIgnore
public Boolean getpassOrFailed {
return active;
}
}
Remember to use both else else it will lead to removing element in deserialization
I've been modeling a domain for a couple of days now and not been thinking at all at persistance but instead focusing on domain logic. Now I'm ready to persist my domain objects, some of which contains IEnumerable of child entities. Using RavenDb, the persistance is 'easy', but when loading my objects back again, all of the IEnumerables are empty.
I've realized this is because they don't have any property setters at all, but instead uses a list as a backing field. The user of the domain aggregate root can add child entities through a public method and not directly on the collection.
private readonly List<VeryImportantPart> _veryImportantParts;
public IEnumerable<VeryImportantPart> VeryImportantParts { get { return _veryImportantParts; } }
And the method for adding, nothing fancy...
public void AddVeryImportantPart(VeryImportantPart part)
{
// some logic...
_veryImportantParts.Add(part);
}
I can fix this by adding a private/protected setter on all my IEnumerables with backing fields but it looks... well... not super sexy.
private List<VeryImportantPart> _veryImportantParts;
public IEnumerable<VeryImportantPart> VeryImportantParts
{
get { return _veryImportantParts; }
protected set { _veryImportantParts = value.ToList(); }
}
Now the RavenDb json serializer will populate my objects on load again, but I'm curious if there isn't a cleaner way of doing this?
I've been fiddeling with the JsonContractResolver but haven't found a solution yet...
I think I've found the root cause of this issue and it's probably due to the fact that many of my entities were created using:
protected MyClass(Guid id, string name, string description) : this()
{ .... }
public static MyClass Create(string name, string description)
{
return new MyClass(Guid.NewGuid(), name, description);
}
When deserializing, RavenDb/Json.net couldn't rebuild my entities in a proper way...
Changing to using a public constructor made all the difference.
Do you need to keep a private backing field? Often an automatic property will do.
public IList<VeryImportantPart> VeryImportantParts { get; protected set; }
When doing so, you may want to initialize your list in the constructor:
VeryImportantParts = new List<VeryImportantPart>();
This is optional, of course, but it allows you to create a new class and start adding to the list right away, before it is persisted. When Raven deserializes a class, it will use the setter to overwrite the default blank list, so this just helps with the first store.
You certainly won't be able to use a readonly field, as it couldn't be replaced during deserialization. It might be possible to write a contract resolver or converter that fills an existing list rather than creating a new one, but that seems like a rather complex solution.
Using an automatic property can add clarity to your code anyway - as it is less confusing whether to use the field or the property.
In one class I have defined the connection string like this
SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = localServer; ;
objConnectionString.UserID = userName;
objConnectionString.Password = password;
objConnectionString.InitialCatalog = selectedDatabase;
where local server = txtHost;--DataSource
userName = txtUsername;
password = txtPassword;
But in my another project I want to access the controls of that project
Currently I am connected with the db like this
using(var sConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]))
But I want to make it such that it would take the value directly from the textboxes used in another project
Waiting for your suggestions .....Can It be done..
You will not bne abble to do this, unless you pass the actual controls to the method in the other project.
Why not rather pass the SqlConnectionStringBuilder object that you set up before hand to the method being called?
In your form with the textbox you will need to create Properties to access the values from the form, e.g.
public string Server
{
get
{
return this.txtHost.Text;
}
}
You will also need to pass a reference of the Form to your other Project, either by referencing the project, or using an shared interface between the two.
In your project where you want to build the connection string, you will need some way of receiving the reference to the Form, such as
public void RunMyQuery(MyForm form)
{
var objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = form.Server;
}
If you have time, consider creating a new project which contain shared interfaces, so you could create an interface such as
public interface IConnectionStringPartProvider
{
string Server { get; }
... other parts
}
and implement this interface on your form
public partial class Form1 : Form, IConnectionStringPartProvider
Then you would not need to reference you form project in your logic class, just let both projects reference the shared project.
This way, your query method could be replaced with
public void RunMyQuery(IConnectionStringPartProvider provider)
{
var objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = provider.Server;
}
I created a Data Source with VB.NET and Visual Studio 2005. I dragged the data source onto my dialog, and VS created the text boxes with the members of my linked Object, a System.Windows.Forms.BindingSource and a System.Windows.Forms.BindingNavigator.
I populate the List (called myList), set myList as the DataSource in the BindingSource, and things work peachy except for the fact that I want this to be read-only. If the user changes something in one of the text boxes, it saves the changes.
I tried creating a read-only collection to bind to the BindingSource, but that didn't solve the problem:
Dim detailsDlg As New dlgMyDetails
Dim readOnlyList As New ReadOnlyCollection(Of MyObjects)(myList)
detailsDlg.MyBindingSource.DataSource = readOnlyList
detailsDlg.ShowDialog()
I guess I could disable all of the text boxes, but that seems a bit heavy-handed, plus I'd probably want to change the font color so that it's easier to read.
Ideally, I probably wouldn't care if users were able to set focus to the text boxes, or even edit the contents, but I just wouldn't want any changes to persist. That is, if someone edited something, used the navigator to go to the next record, and then returned, I'd want it as it was before the user played with it.
Any suggestions / guidance?
Thanks in advance!
From a Model-View-Control perspective, the constraint you want is not on the model or control, but the view. The view should restrict what is editable on the screen.
If it truly is read-only, why not go with a read-only user interface element, ie, a label? The reason you do this is to reduce confusion to the user. If it is a textbox, there is a reasonable expectation that at some point the data becomes editable. If this is not the case, then presenting a disabled textbox is likely not the right UI element to present, rather, as mentioned, a label.
Instead of making a ReadOnlyCollection you can change the property in your class (MyObjects) to ReadOnly or add attribute System.ComponentModel.ReadOnly(true) to your property, example:
class Person
{
public Person(int id, string name, string address)
{
_id = id;
Name = name;
Address = address;
}
private int _id = 0;
public int ID { get { return _id; } }
[System.ComponentModel.ReadOnly(true)]
public string Name { get; set; }
public string Address { get; set; }
}
ID and Name is going to be readonly, sorry if the example is in C#. Hope this helps.
Cheers.