struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hoying, Ken" <Ken_Hoy...@PremierInc.com>
Subject RE: [S2] Checkboxes
Date Fri, 30 Nov 2007 18:50:43 GMT
Thank you for the response.

I had looked at the example, but it really appears to only push the
checkbox results to the action.  I am not sure that it would repopulate
the checkbox with the values.

I do not believe that checkbox list is going to work for me as it does
not give me control on where to put the checkboxes.  I need one in each
row.

It appears that my understanding of how the checkbox works is not
correct.

I am expecting that the checkbox control will call the
getSelectedContracts() method and see if any of these values in the
array it returns matches the value specified in the fieldValue attribute
specified in the checkbox tag.  If there is a match then check the box,
if not don't check it.  However, all of my checkboxes are always being
selected no matter what.

I am also expecting that when submitting the form,
setSelectedContracts() will be called with an array of the values that
were selected.  This does appear to be working with one caveat. If
nothing is selected then I get the error: Invalid field value for field
"selectedContracts".

This obviously does not work the way I thought and I was hoping someone
could maybe explain how it does work as I am really struggling on
gaining an understanding of this tag and its usage.

Thanks in advance,
Ken

-----Original Message-----
From: Martin Gainty [mailto:mgainty@hotmail.com] 
Sent: Friday, November 30, 2007 11:09 AM
To: Struts Users Mailing List
Subject: Re: [S2] Checkboxes

Hi Ken-

struts.xml has this definition of EmployeeAction where results populate
editEmployee.jsp
        <action name="delete"
class="org.apache.struts2.showcase.action.EmployeeAction"
method="delete">
            <result name="error">/empmanager/editEmployee.jsp</result>
            <result
type="redirect">edit-${currentEmployee.empId}.action</result>
        </action>

looking at the results jsp
/empmanager/editEmployee.jsp has a checkbox defined as <s:checkbox
fieldValue="true" label="Married"
name="currentEmployee.married"/>

The EmployeeAction is defined as
package org.apache.struts2.showcase.action;
public class EmployeeAction extends AbstractCRUDAction implements
Preparable {  private Employee currentEmployee;

whereas Employee is defined as
package org.apache.struts2.showcase.model;
public class Employee implements IdEntity {
    private boolean married; //checkbox

so the individual checkbox works fine for setting booleans
http://struts.apache.org/2.0.11/docs/checkbox.html

For handling a list of checkboxes you may want to implement with
checkboxlist?
http://struts.apache.org/2.0.11/docs/checkboxlist.html

M--
----- Original Message -----
From: "Hoying, Ken" <Ken_Hoying@PremierInc.com>
To: <user@struts.apache.org>
Sent: Friday, November 30, 2007 8:45 AM
Subject: [S2] Checkboxes


I am having a difficult time getting checkboxes to work in the following
scenario and am not sure what I am doing wrong.  Any help or guidance
would be greatly appreciated.

I have table which displays several rows.  In the first column of each
row, I have a check box to select that row.  I am keeping track of user
selections so when they return to the page, the checkboxes are
prepopulated with their previous selections.


My Action contains the following:

public Long[] getSelectedContracts()
{
return setSelectedContracts.toArray(new Long[0]); } // end
getSelectedContracts

/**
* This setter takes the provided String[] of selected contract ids.
*/
public void setSelectedContracts(Long[] palngSelectedContracts)
      {

setSelectedContracts.addAll(Arrays.asList(palngSelectedContracts));
} // end setSelectedContracts

My JSP contains the following:

<s:checkbox name="selectedContracts"
fieldValue="${contract.npcContractId}"/>






-----------------------------------------
***Note:The information contained in this message may be privileged and
confidential and protected from disclosure. If the reader of this
message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, you
are hereby notified that any dissemination, distribution or copying of
this communication is strictly prohibited. If you have received this
communication in error, please notify the Sender immediately by replying
to the message and deleting it from your computer. Thank you. Premier
Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


-----------------------------------------
***Note:The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify the Sender
immediately by replying to the message and deleting it from your
computer. Thank you. Premier Inc.  

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message