Announcement Announcement Module
Collapse
No announcement yet.
checking if Object is in a Set in the view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • checking if Object is in a Set in the view

    HI,
    i have two Objects, Page and Html.
    Page contains a Set of html Objects.
    all is working good but now i would to have something like this:

    when displaying the Page-edit-form the List of available Htmls Objects should select the Html objects that are already inside the Set of the Page Object.

    one thing i tried is to use the contains function from Set with the command like:
    Code:
       <c&#58;if test="$&#123;command.htmls.contains&#91;html&#93;&#125;">
    but this doesn't work.

    so have any one a idee or solution how to check if a List or Set contains a Object within the jsp view ?

    thank you.

    mfg Gideon

  • #2
    Instead of storing a Set of 'Html' objects, change your command model object to store a Map with key = html object and value Boolean.TRUE.

    In your JSP, you can now use the JSTL test

    Code:
    <c&#58;if test="$&#123;command.htmls&#91;html&#93;&#125;">
    JSTL does not provide a way to test if an object exists in a List/Set. If you must use a Set in your model, you'll have to write scriptlet code to test for existence of an object in the Set.

    Sanjiv

    Comment


    • #3
      HI,

      ok i want to change to a map, but i have some hibernate mapping problems.

      the mapping i tried is this:

      Code:
      	<class name="Page" table="pages">
      		<id name="id" column="id" unsaved-value="-1">
      			<generator class="identity"/>	            
      		</id>
      		<property name="name" column="name"/>
      		<map name="htmlsInternal" table="page_htmls">
      			<key column="page_id"/>			
      			<index-many-to-many column="html_id" class="Html"/>			
      			<element column="htmls" type="string"/>
      		</map>
      	</class>
      
      	<class name="Html" table="htmls">
      		<id name="id" column="id" unsaved-value="-1">
      			<generator class="identity"/>
      		</id>
      		<property name="name" column="name"/>
      		<property name="code" column="code"/>
      		<property name="datetime" column="datetime"/>
      		<property name="active" column="active"/>
      		<property name="lang" column="lang"/>
      	</class>
      but with this i get the following error:

      Code:
      javax.servlet.jsp.JspTagException&#58; javax.servlet.jsp.JspException&#58; An error occurred while evaluating custom action attribute "test" with value "$&#123;command.htmls&#91;html&#93;&#125;"&#58; The "&#91;&#93;" operator was supplied with an index value of type "de.starline.cms.content.Html" to be applied to a List or array, but that value cannot be converted to an integer. &#40;null&#41; at org.apache.taglibs.standard.tag.el.core.IfTag.condition&#40;IfTag.java&#58;65&#41; at javax.servlet.jsp.jstl.core.ConditionalTagSupport.doStartTag&#40;ConditionalTagSupport.java&#58;122&#41; at
      i seems that the taglibs doesnt' use the map keys

      any idea ?

      Thanks

      mfg Gideon

      Comment


      • #4
        HI,

        ok sorry this was my mistake, i have forgotten to change the map witch is used in the JSP view..

        now i don't get any error but the fields are empty

        <c:out value="${command.htmls[html]}"/>

        is empty (inside the db the htmls column have a attribute true or equals.

        any idea?

        thank you.

        mfg Gideon

        Comment


        • #5
          Sounds like a hibernate mapping issue however I would not add a database column with true/false values just to support the JSTL expression.

          Instead you could have the map with key = Html.id and value Html instance.

          In your JSP, you can change the test to look like

          Code:
          <c&#58;if test="$&#123;!empty command.htmls&#91;html.id&#93;&#125;"/>

          Comment


          • #6
            Hi,
            Originally posted by sjivan

            Instead you could have the map with key = Html.id and value Html instance.

            In your JSP, you can change the test to look like

            Code:
            <c&#58;if test="$&#123;!empty command.htmls&#91;html.id&#93;&#125;"/>
            this is the solution i have testet for some minutes and i works

            thank for your help.

            mfg Gideon

            Comment

            Working...
            X