Announcement Announcement Module
Collapse
No announcement yet.
how do i check for instance of a bean using jstl ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how do i check for instance of a bean using jstl ?

    hi,

    i have a method that validates and creates instance of a bean based on the if condition.

    in my jsp if i have to check for the instance of the bean created using jstl, how do i go about doing it ?

    My code to instantiate a bean :

    Code:
    if (isPresent(productCode)) {
                    	if (isPresentOne(productCode)) {
                        	
                            accountWithSecuritiesViewBean = new PresentOneBean();
                        } else {
                        	accountWithSecuritiesViewBean = new PresentTwoBean();
                        }
                    } else {
                    	                    accountWithSecuritiesViewBean = new NotPresentBean();
                    }
    please let me know how do i have to check in my jsp using jstl to find the instance of the any one of the bean instantiated ??

  • #2
    You could use something like this:

    Code:
    <c:if test="${accountWithSecuritiesViewBean.class.name =='PresentTwoBean'}">
    Or maybe the c:choose tag is more appropiate, you decide.
    I should mention this doesn't really fit in with the whole ModelViewController idea.

    Consider using different views for the different cases.

    Comment


    • #3
      class.name in JSTL no longer works

      In tomcat 7 I am no longer able to query the .class.name of a variable. Don't have any idea why, but it broke my code which used this method. I don't know another solution except to use raw jsp. Any ideas?

      Comment


      • #4
        Use the method syntax

        Originally posted by datbates View Post
        In tomcat 7 I am no longer able to query the .class.name of a variable. Don't have any idea why, but it broke my code which used this method. I don't know another solution except to use raw jsp. Any ideas?
        You can use the getClass() method syntax
        Code:
        <c:if test="${accountWithSecuritiesViewBean.getClass().name =='my.package.PresentTwoBean'}">
        Also the name fetches the fully qualified name of the object

        Comment


        • #5
          awsome!

          Originally posted by adam.g.pullen View Post
          You can use the getClass() method syntax
          Code:
          <c:if test="${accountWithSecuritiesViewBean.getClass().name =='my.package.PresentTwoBean'}">
          Also the name fetches the fully qualified name of the object
          I hadn't started using the method syntax. It rocks! Thanks!

          Comment

          Working...
          X