I was under the impression that we were talking about the question of persisting the Collection on a validation error. You've got validate="false" in the mapping below, so it's not validating. If you set validate="true", I'm almost certain that you'll lose allRoles unless you set the scope to "session". Please yet us know if you get a different result.

Thanks,
David


Mykola Ostapchuk wrote:


Well, you don't have to use session scope and you can clear Collection in
reset() method.

registration.jsp:

<logic:iterate id="item" name="allRoles">
  <html:multibox name="registrationForm" property="selectedRoles">
     <bean:write name="item" property="value"/>
  </html:multibox>
  <bean:write name="item" property="label"/>
</logic:iterate>

struts-config.xml:

<action path="/editUser"
  type="com.name.wos.struts.userAdm.EditRegistrationAction"
  name="registrationForm"
  scope="request"
  validate="false"
  parameter="editUser">
  <forward name="success"  path="/registration.jsp"/>
</action>


registrationForm.java


public String[] getSelectedRoles() {
   return this.selectedRoles;
}
public void setSelectedRoles(String[] selectedRoles) {
   this.selectedRoles = selectedRoles;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
   String [] arrUserRoles={};
   this.setSelectedRoles(arrUserRoles);
}

In registrationAction - just populate selectedRoles array with "checked"
values from DB.
Populate Vector allRoles with all user Roles and put it into context:

   RolesVO curElement;
   RolesBD rolesBD = new RolesBD();
   Enumeration tempAllRoles = rolesBD.selectAllRoles().elements();
   Vector allRoles=new Vector();
   while (tempAllRoles.hasMoreElements()) {
    curElement = (RolesVO)tempAllRoles.nextElement();
    allRoles.addElement(new
LabelValueBean(curElement.getRoleName(),curElement.getRoleId().toString()));
   }
   application.setAttribute("allRoles", allRoles);


----- Original Message ----- From: "David Chelimsky" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, June 18, 2003 1:58 PM
Subject: Re: Multibox persistence problem





I've only been able to make this work w/ session scope. Can you please
post your code so I can see your solution? Thanks.

Mykola Ostapchuk wrote:



Thank you for help - I solved the problem.
Actually, it works with "request" scope well, no need to use session.
The problem was in my code - I didn't put Collection for multibox to the
form bean, but to separate bean...


----- Original Message ----- From: "David Chelimsky" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, June 18, 2003 1:24 AM
Subject: Re: Multibox persistence problem







1. Make sure that you are overriding the reset() method in the


ActionForm.


2. In reset(), make sure you do NOT reset the value of the Collection
that contains your multibox options, but make sure that you DO reset all
other values besides your Collection.
3. set scope="session" as was suggested

The result is that your Collection gets set in your Action and left
alone on validation failure. The other properties are handled per the
quote you referenced below.

As for why it is that Struts doesn't repopulate the Collection for you


from the request, essentially it has no way of knowing that they exist


as they are not in the request when you submit the form. Only the values
you select are. This is not true of text inputs because they return
empty strings, but are still present in the request. I imagine something
could be added to Struts that would add a bunch of hidden fields to the
form in your .jsp that could somehow describe the type of  the members
of the Collection, and then rebuild the collection on the fly based on
those fields. Perhaps this would make more sense after java 1.5 is
released with support for typed Collections.

David

Mykola Ostapchuk wrote:





Doesn't work with session scope too.

"As we know, Struts redirects to the path set in the "input" attribute




for




the action if there are errors present in ActionError object.
The ActionForm object holding the user's data will still be in request.
Thus, any data entered by the user in the form will appear


pre-populated




in




the form."

All the data in <html:text..> tags is pre-populated well. But


multibox -


not...
Any suggestions?



----- Original Message ----- From: "Richard Raquepo" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>;


"Mykola


Ostapchuk" <[EMAIL PROTECTED]>
Sent: Tuesday, June 17, 2003 11:15 PM
Subject: Re: Multibox persistence problem








try setting scope="session" in your action.
HTH
----- Original Message -----
From: "Mykola Ostapchuk" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 18, 2003 10:35 AM
Subject: Multibox persistence problem








Hi,

I'm using multibox to display multiple checkboxes:

<font size=2><pre>
<logic:iterate id="item" name="allRoles">
<html:multibox name="requestUser" property="selectedRoles">
<bean:write name="item" property="value"/>
</html:multibox>
<bean:write name="item" property="label"/>
</logic:iterate>
</pre></font>

Everything works fine, the only problem is - when there's a


validation






error






on my form and it's reposted with error messages, it always return


all


checkboxes unchecked (even if I check some of them before).

How could I keep checkbox values in this situation?


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]










---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]










---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]









--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]









--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to