You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hoying, Ken" <Ke...@PremierInc.com> on 2007/11/30 14:45:45 UTC

[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.  

RE: Action call not calling action method

Posted by Henry Park <He...@isd.lacounty.gov>.
Sorry for the late response.  I had to work on something else.  I am
still having an issue with this.

I did not change any attributes in my struts-default.xml.  Here is a
part of my struts.xml file:

<struts>
  <package name="default" extends="struts-default">
    <default-interceptor-ref name="paramsPrepareParamsStack"/>
    
    <!-- Menu -->   
    <action name="Menu" class="action.MenuAction" method="list">
      <result name="success">/jsp/include/menu.jsp</result>
      <interceptor-ref name="paramsPrepareParamsStack"/>
    </action>

...

Henry


-----Original Message-----
From: Martin Gainty [mailto:mgainty@hotmail.com] 
Sent: Tuesday, December 04, 2007 1:37 PM
To: Struts Users Mailing List
Subject: Re: Action call not calling action method

Henry

difficult to say without seeing the interceptor stack from
struts-default.xml
Please post to group

M--
LA County ..465 square miles of constantly interfacing humanity -
Dragnet
quote from Dan Ackroyd

----- Original Message -----
From: "Henry Park" <He...@isd.lacounty.gov>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, December 04, 2007 11:48 AM
Subject: Action call not calling action method


Hello everyone, I am having a really strange issue.  In my application I
have a menu bar and a main content area. The menu bar and main content
area are populated separately using an Ajax call to their respective
action methods. They are automatically called/populated when I log into
my application.  So when I log in, the main content area and menu bar
are successfully displayed.

When I first log into my application, everything gets loaded properly
and the appropriate action methods are called.  However when I try to
call my menu action again, it does not call my action method.  For
example, if my action call looks like this:


getUrl("MenuAction!list.action")


and my Menu Action class looks like this:


public class MenuAction extends ActionSupport implements Preparable {

  public void prepare() throws Exception {
    log.debug("in prepare");
  }

  public String doList() {
    log.debug("doList");
    return SUCCESS;
  }
}


It enters my 'prepare()' method but does not enter my doList() method.
But on the first initial call, it does enter doList().  It seems like I
can only 'get into' the doList() method once. I even entered the action
call manually in my browser address bar but it still only enters my
prepare() method.

Here is the really strange part... on my development machine, everything
works perfectly. All the methods get called successfully.  The above
only happens when I access it from a different computer. Any ideas? I've
been trying to figure this out for days.

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



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


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


Re: Action call not calling action method

Posted by Martin Gainty <mg...@hotmail.com>.
Henry

difficult to say without seeing the interceptor stack from
struts-default.xml
Please post to group

M--
LA County ..465 square miles of constantly interfacing humanity - Dragnet
quote from Dan Ackroyd

----- Original Message -----
From: "Henry Park" <He...@isd.lacounty.gov>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, December 04, 2007 11:48 AM
Subject: Action call not calling action method


Hello everyone, I am having a really strange issue.  In my application I
have a menu bar and a main content area. The menu bar and main content
area are populated separately using an Ajax call to their respective
action methods. They are automatically called/populated when I log into
my application.  So when I log in, the main content area and menu bar
are successfully displayed.

When I first log into my application, everything gets loaded properly
and the appropriate action methods are called.  However when I try to
call my menu action again, it does not call my action method.  For
example, if my action call looks like this:


getUrl("MenuAction!list.action")


and my Menu Action class looks like this:


public class MenuAction extends ActionSupport implements Preparable {

  public void prepare() throws Exception {
    log.debug("in prepare");
  }

  public String doList() {
    log.debug("doList");
    return SUCCESS;
  }
}


It enters my 'prepare()' method but does not enter my doList() method.
But on the first initial call, it does enter doList().  It seems like I
can only 'get into' the doList() method once. I even entered the action
call manually in my browser address bar but it still only enters my
prepare() method.

Here is the really strange part... on my development machine, everything
works perfectly. All the methods get called successfully.  The above
only happens when I access it from a different computer. Any ideas? I've
been trying to figure this out for days.

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



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


Action call not calling action method

Posted by Henry Park <He...@isd.lacounty.gov>.
Hello everyone, I am having a really strange issue.  In my application I
have a menu bar and a main content area. The menu bar and main content
area are populated separately using an Ajax call to their respective
action methods. They are automatically called/populated when I log into
my application.  So when I log in, the main content area and menu bar
are successfully displayed.  

When I first log into my application, everything gets loaded properly
and the appropriate action methods are called.  However when I try to
call my menu action again, it does not call my action method.  For
example, if my action call looks like this:


getUrl("MenuAction!list.action")


and my Menu Action class looks like this:


public class MenuAction extends ActionSupport implements Preparable {

  public void prepare() throws Exception {
    log.debug("in prepare");
  }

  public String doList() {
    log.debug("doList");
    return SUCCESS;
  }
}


It enters my 'prepare()' method but does not enter my doList() method.
But on the first initial call, it does enter doList().  It seems like I
can only 'get into' the doList() method once. I even entered the action
call manually in my browser address bar but it still only enters my
prepare() method.

Here is the really strange part... on my development machine, everything
works perfectly. All the methods get called successfully.  The above
only happens when I access it from a different computer. Any ideas? I've
been trying to figure this out for days.

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


RE: [S2] Checkboxes

Posted by Dave Newton <ne...@yahoo.com>.
Oh, that's clever, I don't think I would have thought
of that, and it's a lot quicker than my ideas ;)

d.

--- "Hoying, Ken" <Ke...@PremierInc.com> wrote:

> Thanks, Dave!
> 
> This got me moving in the right direction.  For
> future reference, I
> ended using the checkboxlist tag inside of my loop
> and set the list
> attribute to a single value so I would only get the
> one option.  This
> seems to have solved my issue.
> 
> Thanks,
> Ken
> 
> -----Original Message-----
> From: Dave Newton [mailto:newton.dave@yahoo.com] 
> Sent: Friday, November 30, 2007 6:06 PM
> To: Struts Users Mailing List
> Subject: RE: [S2] Checkboxes
> 
> A single checkbox, AFAIK, only expects to check a
> single value, not an
> array or collection.
> 
> I would consider using a modified version of the
> checkboxlist tag if
> it's just a matter of the rendered HTML you're
> having an issue with.
> 
> d.
> 
> --- "Hoying, Ken" <Ke...@PremierInc.com> wrote:
> 
> > 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" <Ke...@PremierInc.com>
> > To: <us...@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
> 
=== message truncated ===


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


RE: [S2] Checkboxes

Posted by "Hoying, Ken" <Ke...@PremierInc.com>.
Thanks, Dave!

This got me moving in the right direction.  For future reference, I
ended using the checkboxlist tag inside of my loop and set the list
attribute to a single value so I would only get the one option.  This
seems to have solved my issue.

Thanks,
Ken

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Friday, November 30, 2007 6:06 PM
To: Struts Users Mailing List
Subject: RE: [S2] Checkboxes

A single checkbox, AFAIK, only expects to check a single value, not an
array or collection.

I would consider using a modified version of the checkboxlist tag if
it's just a matter of the rendered HTML you're having an issue with.

d.

--- "Hoying, Ken" <Ke...@PremierInc.com> wrote:

> 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" <Ke...@PremierInc.com>
> To: <us...@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
> 
> 


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


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


RE: [S2] Checkboxes

Posted by Dave Newton <ne...@yahoo.com>.
A single checkbox, AFAIK, only expects to check a
single value, not an array or collection.

I would consider using a modified version of the
checkboxlist tag if it's just a matter of the rendered
HTML you're having an issue with.

d.

--- "Hoying, Ken" <Ke...@PremierInc.com> wrote:

> 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" <Ke...@PremierInc.com>
> To: <us...@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
> 
> 


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


RE: [S2] Checkboxes

Posted by "Hoying, Ken" <Ke...@PremierInc.com>.
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" <Ke...@PremierInc.com>
To: <us...@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


Re: [S2] Checkboxes

Posted by Martin Gainty <mg...@hotmail.com>.
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" <Ke...@PremierInc.com>
To: <us...@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