• Post Reply Bookmark Topic Watch Topic
  • New Topic

AppConstants in JSP?  RSS feed

 
Matt Hoffman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to refer to a value from the AppConstants file into a jsp? Anyone have a example of this?
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi matt,
can you explain in a bit more details what you are trying to do. I am just wondering....before giving an answer that does not cover your question.
regards
 
Matt Hoffman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.. I have a value in the database that I need to check. The value is a 7 so I want to display certain text on the screen when the value it is a 7. I don't want to hard code the number in the application.

Here is what I have now..

<c:choose>
<c:when test="${ test.test1.name == '7'}">
<bean:message key='message.test'/>
</c:when>
<c therwise>
 
</c therwise>
</c:choose>
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
write a custom tag that does the job for you. Take a look at:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html
chapter 15. Then this tag goes to the database and check the value. Then this value can also print of the right text that could also be variable from the database.
regards, and good luck
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several problems in doing so.

First, we need to build up our own taglib, which cannot make good use of existing JSTL and EL functions.

Also, as JSP is already in the presentation, should we make a DB connection at the presentation, instead of getting the value from Controller and pass to the view?

Third, I guess he just wanna replace the value "7" by a Java Constant, and that value, I suppose, is coded in a Java class. I am not sure whether EL can accept scriptlet, have you tried to use <%=xxx.seven%> to replace it? where xxx is the Java class that contain the constant. Otherwise, you might consider to put the constant into request scope, so that EL can access it by ${test_value == seven}.

Nick
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!