You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ashish Mishra <am...@webifyservices.com> on 2003/08/23 09:44:54 UTC

Naming Checkboxes at Runtime

Hi,

I want to create the checkboxes in form dynamically. 
for loop solves the problem as far as displaying the checkbox.

But how would i dynamically name the checkbox, as the name of these checkboxes are comming from the database.


Regards

Ashish

Re: Naming Checkboxes at Runtime

Posted by Harish Krishnaswamy <hk...@comcast.net>.
You may do something like the following...

public class User
{
    .....
    private String userId;
    private boolean status;
    .....
}

public class Group
{
    .....
    private String groupId;
    private SortedMap users;   // keyed by userId
    .....
}

public abstract class YourPage extends BasePage implements IActionListener
{
    .....
    // create a groupsProp Map via property-specification
    public abstract Map getGroupsProp();
    public abstract void setGroupsProp(Map groupsMap);

    public Map getGroups()
    {
       Map groupsMap = getGroupsProp();
       if (groupsMap == null)
       {
          // build groups Map from DB
          setGroupsProp(groupsMap);
       }
       return groupsMap;
    }

    public void actionTriggered(IComponent component, IRequestCycle cycle)
    {
       if (cycle.isRewinding())
       {
          // Build the Group and User objects based on the current 
groupId and UserId and add it to the groups Map property
       }
    }
}

Your.page specification
.....
    <property-specification name="groupsProp" type="java.util.Map"/>
    <property-specification name="groupId" type="java.lang.String"/>
    <property-specification name="userId" type="java.lang.String"/>

    <component id="groupsLoop" type="ListEdit">
        <binding name="source" expression="groups"/>
        <binding name="value" expression="groupId"/>
        <binding name="listener" expression="page"/>
    </component>
   
    <component id="usersLoop" type="ListEdit">
        <binding name="source" expression="users"/>
        <binding name="value" expression="userId"/>
        <binding name="listener" expression="page"/>
    </component>

    <component id="status" type="Checkbox">
        <binding name="selected" 
expression="groups[groupId].users[userId].status"/>
    </component>
.....

Your.html template
.....
    <table>
        <tr jwcid="groupsLoop" element="tr">
             <td>
                <table>
                    <tr jwcid="usersLoop" element="tr">
                         .....
                        <td><input type="checkbox" jwcid="status"/></td>
                         .....
                    </tr>
                </table>
             </td>
        </tr>
    </table>
.....

Hope this helps.

-Harish

Ashish Mishra wrote:

>Hi Harish,
>
>I would like to clear the picture as to what i want.
>
>I have an html page which is used to dispaly the groups and user in that
>group in table format.
>
>i.e.
>
>Suppose if I have 3 groups so i will have three table.
>And contents of each table will be the user in that particular group.
>In this table we will have two columns,
>One is user name belonging to respective group and other colum will contain
>the checkbox.
>And we have a delete button at the end of the page.
>
>On click of delete button,depending upon the checkboxes that are checked ,
>the user should be deleted from the user group.
>
>This is the basic functionality of the page.
>
>The main point to be remembered is that Usergroup and no of users(in that
>group) are dynamic.
>
>I hope the things r clear now.
>
>Regards
>
>Ashish
>----- Original Message -----
>From: "Harish Krishnaswamy" <hk...@comcast.net>
>To: "Tapestry users" <ta...@jakarta.apache.org>
>Sent: Saturday, August 23, 2003 2:01 PM
>Subject: Re: Naming Checkboxes at Runtime
>
>
>  
>
>>Tapestry component names are dynamically generated by the framework. The
>>user need not and should not rely on the naming as far as I know. What
>>exactly are you trying to do? More info would be helpful in answering
>>your question.
>>
>>-Harish
>>
>>Ashish Mishra wrote:
>>
>>    
>>
>>>Hi,
>>>
>>>I want to create the checkboxes in form dynamically.
>>>for loop solves the problem as far as displaying the checkbox.
>>>
>>>But how would i dynamically name the checkbox, as the name of these
>>>      
>>>
>checkboxes are comming from the database.
>  
>
>>>Regards
>>>
>>>Ashish
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>    
>>
>
>
>  
>

Re: Naming Checkboxes at Runtime

Posted by Harish Krishnaswamy <hk...@comcast.net>.
Tapestry component names are dynamically generated by the framework. The 
user need not and should not rely on the naming as far as I know. What 
exactly are you trying to do? More info would be helpful in answering 
your question.

-Harish

Ashish Mishra wrote:

>Hi,
>
>I want to create the checkboxes in form dynamically. 
>for loop solves the problem as far as displaying the checkbox.
>
>But how would i dynamically name the checkbox, as the name of these checkboxes are comming from the database.
>
>
>Regards
>
>Ashish
>  
>


RE: Naming Checkboxes at Runtime

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
I think you are still thinking in a JSP mindset.

You shouldn't ever have to care what the names of the checkboxes are.

Each checkbox is going to map to a boolean property of some object (possibly the page which contains
it).  It will read the boolean property on render, set the boolean property on form submit.

It is common to create a synthetic property of type boolean which, behind the scenes, is responsible
for (say) adding or removing elements from a Set.

Need more details about your problem space to provide more guidance.

--
Howard M. Lewis Ship
Creator, Tapestry: Java Web Components
http://jakarta.apache.org/tapestry
http://jakarta.apache.org/commons/sandbox/hivemind/
http://javatapestry.blogspot.com

> -----Original Message-----
> From: Ashish Mishra [mailto:amishra@webifyservices.com] 
> Sent: Saturday, August 23, 2003 3:45 AM
> To: Tapestry users
> Subject: Naming Checkboxes at Runtime
> 
> 
> Hi,
> 
> I want to create the checkboxes in form dynamically. 
> for loop solves the problem as far as displaying the checkbox.
> 
> But how would i dynamically name the checkbox, as the name of 
> these checkboxes are comming from the database.
> 
> 
> Regards
> 
> Ashish
>