Results 1 to 6 of 6

Thread: checking if Object is in a Set in the view

  1. #1
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    143

    Default 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. #2
    Join Date
    Sep 2004
    Location
    Boston, US
    Posts
    130

    Default

    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

  3. #3
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    143

    Default

    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

  4. #4
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    143

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Location
    Boston, US
    Posts
    130

    Default

    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;"/>

  6. #6
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    143

    Default

    Hi,
    Quote 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

Similar Threads

  1. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  4. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •