简体   繁体   English

JSTL / JSP动态表单页面状态

[英]JSTL/JSP dynamic form page state

Working on a large Web app, I have houndresds of JSPs. 在大型Web应用程序上工作时,我有很多JSP。 Each JSP includes (ONLY) a set of internal tags, for instance: 每个JSP包含(仅)一组内部标记,例如:

<AAA:INPUT value="bbb" state="<%=getPageState()"/>

This tag is rendered into an HTML input field, with a readonly/enabled state, based on the return value from getPageState(). 基于getPageState()的返回值,此标记呈现为具有只读/启用状态的HTML输入字段。

This basically allows me to set the complete page as enabled/disabled from a single entry point. 基本上,这使我可以从单个入口点将整个页面设置为启用/禁用。

I don't like this (mainly because it drives me away from writing the HTML I want and I need to maintain attributes for each HTML attribute I want), I know I can something similar on client side with JavaScript. 我不喜欢这样(主要是因为它使我无法编写所需的HTML,并且我需要为所需的每个HTML属性维护属性),我知道我可以在JavaScript方面实现类似的功能。 Are there other approachs to control the state of a complete JSP form in a single point on the web-server side? 还有其他方法可以在Web服务器端的单个点上控制完整JSP表单的状态吗?

The way I would go about this would be to convert the getPageState() method into a tag, and then use this tag within your custom tags. 我要解决的方法是将getPageState()方法转换为标签,然后在自定义标签中使用此标签。 That way, you don't need to explicitly pass in the page-state on every invocation of your custom tag. 这样,您无需在每次调用自定义标记时显式传递页面状态。

Of course, this means that you would have to modify all your custom tags to use this new tag, but I think that's better than having your code littered with explicit calls to get the page state. 当然,这意味着您必须修改所有自定义标签才能使用此新标签,但我认为这比让代码中包含明确的调用来获取页面状态更好。 Not to mention, an opening for inconsistencies if a developer forgot to check the page state. 更不用说,如果开发人员忘记检查页面状态,就会出现不一致的情况。

Also, now the decision as to how the element needs to be rendered rests in the custom tag itself (where it belongs). 而且,现在有关如何呈现元素的决定取决于自定义标记本身(它所属的位置)。

The only problem I see is that now you have to make multiple (redundant) calls per element to get the page state, which is not that efficient. 我看到的唯一问题是,现在您必须对每个元素进行多次(冗余)调用才能获取页面状态,但效率不高。 To get around this problem, you can have your custom tag (that gets the page state) set a page attribute, and have your custom tags inspect this page attribute to decide if the form element should be disabled or not (another way would be to create a variable with the scope AT_END ). 要解决此问题,您可以让您的自定义标签(获取页面状态)设置一个页面属性,并让您的自定义标签检查该页面属性,以确定是否应禁用表单元素(另一种方法是创建范围为AT_END的变量)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM