I am trying to create an application that will allow the users to change text and labels in an XML file, which in turn I will pull into the JSP. The idea is that I will code the static portion of the JSP with the include, but there after if they want to change a text paragraph or field label, it can be done in the XML file and will be available to the JSP next time the JSP is run.
The XML which is being parsed is as follows: <Paragraph> <Column> <FixedData><input type="text" size="2" name="oldState" value="<%= newState != null ? newState : "" %>"> </FixedData> <Description>Previously titled in </Description> </Column> </Paragraph>
The problem is that at run time the piece of Java code in the JSP is run and it outputs the description, but the variable newState which is determined by the Java code that is being pulled in from the XML file is not resolved. Any ideas on how I can make this work?
Exactly why do you think it should be pulling in the external XML for every request? This is a prime example of code that should be in a servlet or a bean class. Writing extensive Java logic in JSP is just hard to read and hard to debug. Bill
posted 15 years ago
I will move it to a bean. This is just a prototype. Even if this is in a bean, I will still have the same problem. At runtime, the code to access the bean will be resolved, but the expression coded in the xml will not have been resolved.
I want to put the text and labels in XML so that the users can change any field descriptions or text at any time and we don't have to make code changes. Next time the JSP is run, the new labels as defined in the XML will be pulled in and displayed. At the same time, through the use of html in the XML, they can change the format/font/color of the labels etc. A really scaled down versions of a dynamic content management system. It works really well in all instances where there is straight HTML in the XML attribute. The problem comes in when we have forms with fields and the value of the field needs to be resolved at runtime. The field (and expression to resolve it) is defined in the XML, but as I said before, the bean\java code gets resolved but it doesn't resolve the expression coded in the XML.
This thread just screams ResourceBundle at me. I'm not even sure it would be appropriate in this situation, but XML seems like an overkill for the needed feature described.
If you use JSP 2.0's message Resource Bundle features, you can just define all these replacable texts in a .properties file. Then you can even internationalize it if need be.
posted 15 years ago
The XML string will contain '<input type="text" size="2" name="oldState" value="<%= newState != null ? newState : "" %>">' If I write that out in the response, will value="<%= newState != null ? newState : "" %>"> get resolved?