aspose file tools*
The moose likes Struts and the fly likes Html:checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Html:checkbox" Watch "Html:checkbox" New topic
Author

Html:checkbox

Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
Hi, I have problem with checkbox

<logic:equal value="Y" name="productProjectItem" property="active" >
< html:checkbox name ="Form" property="active" value="false"
onlick="JavaScript:activeCheckBox(< c ut value="${productProjectItem.Id}" />,
< c ut value="${productProjectItem.projectId}" />,'< c ut value="${productProjectItem.productLineId}" />',
>c ut value="${productProjectItem.TypeId}" /<,this);"> </html:checkbox >

>/logic:equal <

1. its throwing an error that Kind ${productProjectItem.Id} has no value.

2. when active is "Y" I want the checkbox to be checked how to do that.


Kind of Urgent

Thanks
Infyniti

[ December 06, 2005: Message edited by: infyniti Molugu ]
[ December 06, 2005: Message edited by: infyniti Molugu ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you are going to embed EL expressions inside a struts tag, you must use the struts-el version of the tags. If you are using the struts-el tags, just put the EL expression without an enclosing <cut /> tag. Also, one of the quirks of using tags within tags is that if you use a double quote anywhere in the enclosed tag, you must use a single quote outside.


here's an example:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el"
prefix="html-el"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<html-el:checkbox name="Form" property="active" value="true"
onklick="JavaScript:activeCheckBox(${productProjectItem.Id}, ${productProjectItem.projectId}, ${productProjectItem.productLineId})" />

This assumes that struts-el.jar is in your classpath.


Another problem with your code is that you probably want the value attribute to be "true". The value attribute specifies what value will be given to the property if the box is checked. The html:checkbox tag automatically checks or unchecks the box based on the current value of the property you specified.


Merrill
Consultant, Sima Solutions
Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
<logic:equal value="N" name="productProjectItem" property="active" >
<td class="centered">
<input type="checkbox" name="active" value="true"
onklick="JavaScript:activeCheckBox(${productProjectItem.Id}" />,
<c ut value="${productProjectItem.projectId}" />,'<c ut value="${productProjectItem.productLineId}" />',
<c ut value="${productProjectItem.issueTypeId}" />,this) ;">
</td>
</logic:equal>

<logic:equal value="Y" name="productProjectItem" property="active">
<td class="centered">
<input type="checkbox" name="active" checked value="false"
onklick="JavaScript:activeCheckBox(<c ut value="${productProjectItem.Id}" />,
<c ut value="${productProjectItem.projectId}" />,'<c ut value="${productProjectItem.productLineId}" />',
<c ut value="${productProjectItem.issueTypeId}" />,this);">
</td>
</logic:equal>

This is what I did..ie. i have combined to Struts tags and html tags....
Now i want to use only struts tags.
As per the previouse discussion i have removed cout
When the active value picked from database is Y then the the check box should be checked else it should be unchecked. That can be checked or unchecked and submitted to database with all other values.

Regards
Anjana.
[ December 06, 2005: Message edited by: infyniti Molugu ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you want to use the struts html:checkbox tag, the first thing you have to do is create a Form bean (Class that extends ActionForm) that has an "active" property. Prior to displaying this page, set the active property to true or false based on your database, or whatever crieteria you use. If you then include an html:checkbox tag with property="active", struts will automatically check or uncheck the box based on the value of the active property in your form bean.

if the form bean is in session scope, you need to override the reset() method of the form bean to set the value of active to false.
Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
sorry Merrill, may be I am submitting the same question again and again...as u said i have used el tags please find the code belwo

<logic:equal value="N" name="productProjectItem" property="active" >
<td class="centered">
<html-el:checkbox name ="productProjectItem" property="active" value="Y"
onklick="JavaScript:activeCheckBox('${productProjectItem.Id}',
'${productProjectItem.projectId}','${productProjectItem.productLineId}' ,
'${productProjectItem.issueTypeId}' ,this);"> </html-el:checkbox>
</td>
</logic:equal>

<logic:equal value="Y" name="productProjectItem" property="active" >
<td class="centered">
<html-el:checkbox name ="productProjectItem" property="active" value="Y"
onklick="JavaScript:activeCheckBox('${productProjectItem.Id}',
'${productProjectItem.projectId}','${productProjectItem.productLineId}' ,
'${productProjectItem.issueTypeId}' ,'N');"> </html-el:checkbox>
</td>
</logic:equal>

now the problem the jsp is getting properly display but when i uncheck the checkbox which is already checked then the value N should go to databse..u must have noticed in seoncd logic state (bolded N) i have harded coded it ..if i say this then value is going to databse as Y but i want N when i check the already checked ones and if check the already unchecked one then Y shoould go to database. the first logic is working fine when i display its showing as unchecked when active N and when check it "Y" is gong to dabase. But the second logic statement is giving trouble.

can u please suggest me how to remove that coded N value and pass so that it works as I mentioned.

Thanks
Infyniti.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If I understand you correctly, it looks like your javascript function activeCheckBox is what is actually causing the value to be saved to the database, right?

If that's the case, do the following:
  • Change the activeCheckBox function so that the last parameter it accepts is a boolean. Then convert the boolean to a Y or N.
  • Eliminate the logic:equal tags, and only include one copy of the checkbox. The last parameter passed to the activeCheckBox function in the onKlick event should be this.checked. This will evaluate to true if the user is checking the box and false if the user is unchecking it.


  • Here's an example of the activeCheckBox function:

    function activeCheckBox(x, y, z, checked) {
    var yOrN = (checked)?"Y":"N";
    ... the rest of the function;
    }
    Anant Rao
    Ranch Hand

    Joined: Nov 12, 2004
    Posts: 126
    Thanks for ur patience Merrill. That was stupid thing I was doing taking two logic equal statements.It worked out as u said.


    thanks once again
    Infyniti.
     
    Don't get me started about those stupid light bulbs.
     
    subject: Html:checkbox