Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2170

Converting Struts Options

From "Oleg Konovalov" <oleg.konovalov@THRWHITE.remove-dii-this>
Subject Converting Struts Options
Message-ID <KQEri.7686$8u1.6082@trnddc07> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:37 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.programmer
Hi,

I wrote a [sample] simple screen with 2 html:selects [fromList, toList] and 
2 buttons Add & Remove
using "html:optionscollection" tag and now need to rework the code using 
"html:options collection="

<html:select property='selectedFromIds' multiple="true">
    <html:optionsCollection property='fromList'/>
</html:select>


to something like [that is a piece of my existing application which I have 
to follow since it already integrates to other things - gets populated from 
DB, etc.]:
<html:select property="submissionType" multiple="true" 
styleId="submissionTypeID">
  <html:options collection="SubmissionType" property="submissionTypeID" 
labelProperty="submissionType" />
</html:select>
where the only related thing I have declared in the Form is:
public String submissionType[];

   SubmissionType is a Class SubmissionType:
public class SubmissionType  {
   private String submissionType;
   private String submissionTypeID;
    ... getters & setters
    }

I tried directly:
<html:select property='selectedFromIds' multiple="true">
    <html:options Collection='fromList'/>
</html:select>

So how do I convert the tags and probably the Java code as well ?

HTTP error:500  JspException: Cannot find bean under name fromList,
although have     List fromList = form.getFromList ();

The original sample code is below:

Action:
public class StrutsAction2 extends DispatchAction {

    public ActionForward init(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) throws Exception {
        System.out.println("In Init");
        ControlForm form = (ControlForm)actionForm;
        List fromList = form.getFromList();
        fromList.clear();
        fromList.add(new LabelValueBean("v1", "k1"));
        fromList.add(new LabelValueBean("v2", "k2"));
        fromList.add(new LabelValueBean("v3", "k3"));

        return actionMapping.findForward("init");
    }


    public ActionForward add(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) throws Exception {
        System.out.println ("In Add");
        ControlForm form = (ControlForm)actionForm;

        List fromList = form.getFromList();
        List toList = form.getToList();

        String[] selectedFromIds = form.getSelectedFromIds ();

        for(int i=0; i < selectedFromIds.length; i++) {
            String id = selectedFromIds[i];

            Iterator iterator = fromList.iterator();

            boolean ok = false;
            while( iterator.hasNext() && !ok) {
                LabelValueBean lvb = (LabelValueBean)iterator.next();

                if(lvb.getValue().equalsIgnoreCase(id)) {
                    if(!toList.contains(lvb)) {
                      toList.add(lvb);
                    }
                    ok = true;
                }
            }
        }
        return actionMapping.findForward("add");
    }


    public ActionForward remove(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) throws Exception {
        System.out.println ("In Remove");

        ControlForm form = (ControlForm)actionForm;

    List toList = form.getToList();

        String[] selectedToIds = form.getSelectedToIds();

        for(int i=0; i < selectedToIds.length; i++) {
            String id = selectedToIds[i];

            Iterator iterator = toList.iterator();

            boolean ok = false;
            while(iterator.hasNext() && !ok) {
                LabelValueBean lvb = (LabelValueBean)iterator.next();

                if(lvb.getValue().equalsIgnoreCase(id)) {
                    iterator.remove();
                    ok = true;
                }
            }
        }
        return actionMapping.findForward("remove");
    }
}


Form:
public class ControlForm extends ActionForm {
    private String[] selectedFromIds;
    private String[] selectedToIds;
    private List fromList = new ArrayList();
    private List toList = new ArrayList();
... getters/setters
}

JSP:
<html:form action="/action2" method='POST'>
  <table>
      <tr>
        <td>
          <%--html:select property='selectedFromIds' multiple="true">   <!--  
that how it is in my sample >
            <html:optionsCollection property='fromList'/>
          </html:select--%>

          <%--html:select property="submissionType" multiple="true" 
styleClass="selectSmall" styleId="submissionTypeID">   <!-- that's how it is 
in my Real application -->
            <html:options collection="SubmissionType" 
property="submissionTypeID" labelProperty="submissionType" />
          </html:select--%>

          <html:select property="selectedFromIds" multiple="true">   <!--  
Shows me error that fromList bean is not declared -->
            <html:options collection="fromList"/>
          </html:select>
        </td>
    <td>
          <input type="submit" onclick="form.action =' 
action2.do?methodToCall=add'" value="Add"/>
        </td>
        <td>
          <input type="submit" onclick="form.action 
='action2.do?methodToCall=remove'" value="Remove"/>
        </td>
        <td>
          <html:select property='selectedToIds' multiple="true">  <!--  
original sample to be converted -->
              <html:optionsCollection property='toList'/>
          </html:select>
        </td>
      </tr>
  </table>
  </html:form>

Any help is Very appreciated.

Thank you in advance,
Oleg.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | Next | Find similar | Unroll thread


Thread

Converting Struts Options "Oleg Konovalov" <oleg.konovalov@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

csiph-web