如何通过UI启用/禁用struts2网页中的必填字段

时间:2012-03-12 04:36:01

标签: javascript jquery jquery-ui jsp struts2

在我的网页中,假设有10个字段,其中4个字段是必填字段。

在运行时,任何人都可以启用非强制性的少数字段。当下次重新启动应用程序时,它应该将字段显示为必需字段,而不显示新添加的必填字段的业务逻辑

(我想通过UI强制增加2个字段,并且只显示新添加的必填字段的业务逻辑,请填写此字段。)

1 个答案:

答案 0 :(得分:1)

每个操作都与一个包相关联。因此,package_name和action_name唯一标识您的操作,并为required_attribute表创建一个好的密钥。在数据库中,您将存储PK和setter属性(setter的字符串名称)以及用户ID。

您将创建一个将访问数据库的RequiredFieldService。

RequiredFieldService接口可能包含:

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

我会在我的validate方法中使用上面的服务,因为我想我想自定义错误消息但是如果你只是想产生标准错误,拦截器可以工作,这会设置字段错误消息(尽管它会更容易让验证方法首先工作)。


以上内容负责验证,但不处理需要管理界面的UI部分。您将需要一些可以显示项目中所有操作的内容(类似于配置浏览器插件),一旦选择了一个操作,它将显示您可以使用一组复选框选择的所有公共设置器。需要。通过这样的选择和上述界面的实现,你应该好好去。