简体   繁体   中英

JSTL/JSP dynamic form page state

Working on a large Web app, I have houndresds of JSPs. Each JSP includes (ONLY) a set of internal tags, for instance:

<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().

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. Are there other approachs to control the state of a complete JSP form in a single point on the web-server side?

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. 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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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