VIVEK
VIVEK

Reputation: 33

how to Enable/Disable Mandatory fields in struts2 web page through UI

In my web Page suppose 10 fields are there, in which 4 fields are mandatory.

At run time anyone can enable few fields that is not mandatory into mandatory. When next time restart application it should show that fields as mandatory and no business logic for newly added mandatory fields

( I want to make 2 more fields mandatory through UI and no business logic for newly added mandatory fields only it will show,please fill this fields.)

Upvotes: 1

Views: 739

Answers (1)

Quaternion
Quaternion

Reputation: 10458

Every action is associated with a package. So package_name and action_name uniquely identifies your action and would make a good key for a required_attribute table. In the database you'll store the PK and setter properties (string names of setters) along with the user id.

You will create a RequiredFieldService which will access the database.

RequiredFieldService interface will probably contain:

public void setRequiredActionFieldsPerUser(String namespace, String action, Class<T> actionClass, List<String> requiredSetters, int userId); //The class is passed in to make it easier to use reflection (or preferably Apache bean utils to verify that the setters actually exist)

public List<String> getRequiredActionFieldsPerUser(String namespace, String action, int userId);//if you provide a Class in the parameters you can test if the interface has changed and throw an exception, or simply remove those attributes from the db

I would use the above service in my validate method, because I think I would like to customise the error messages but if you simply want to produce a standard error an interceptor could work which would set the field error messages (although it would be easier to get the validate method working first).


The above takes care of validation but does not take care of the UI part, which requires an admin interface. You will want something that can show all the actions in your project (something like the config browser plugin) upon selecting an action it will display all the public setters for which you'll be able to select with a set of check boxes which ones are required. With such a set of selections and the implementation of the above interface you should be good to go.

Upvotes: 1

Related Questions