1

I want to know if is possible to set in a bean String Array a property received by an url parameter.

I have this:

The bean, in your FormHandler class:

private String[] clientName;

The JSP file:

<dsp:setvalue bean="ClientFormHandler.clientName" paramvalue="clientName" />

In this way, I got this error in my screen:

**** Error Wed Jul 06 13:53:06 BRT 2016 Trying to set value of /clientCom/app/formHandlers/ClientFormHandler.clientName, this IllegalArgumentException occurred: java.lang.IllegalArgumentException: argument type mismatch

This isn't working, so I tryed this, but without success too...

<dsp:setvalue bean="ClientFormHandler.clientName[0]" paramvalue="clientName" />

and I got this error

**** Error Wed Jul 06 13:55:34 BRT 2016 1467824134007 /atg/dynamo/servlet/dafpipeline/ProtocolSwitchServlet
atg.droplet.DropletException: Cannot set elements of a multi-valued prop erty if property is not a List and if it is missing an indexed property method

Can I do something like this in a JSP file, without change the java class?

Tks.

Murcilha
  • 25
  • 9

1 Answers1

1

I haven't found an example with an array but I suggest that you work with MVC architecture

you can set your bean parameter by :

1/ adding a form in your JSP where you put the value that you want in an input hidden

<form method="post" action="MYSERVLET">
    <input type="hidden" name="VAL" value="NEW_NAME"/>

    <input type="submit" value="click"/>
        </form>

2/ create a bean where you put these methods

public class bean {
 private String[] clientName ={"tt","bb","gg","ff","tt","gg"};//just for verification

    public String[] getClientName() {
        return clientName;
    }

    public void setClientName(String[] clientName) {
        this.clientName = clientName;
    }

    public void NewVal(String newVal, int index){
    this.clientName[index] = newVal; 
     }

     public String getVal( int index){
    return this.clientName[index] ; 
     }
}

3/create a servlet(MYSERVLET)

change doPost to

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

 String val  =  request.getParameter("VAL");
 bean Mybean= new bean();
 Mybean.NewVal(val, 0);
 System.out.println("--------------------"+Mybean.getVal(0));
}

result :

 --------------------NEW_NAME (in server logs) 

the first position of array bean is changed to "NEW_NAME"

Taha
  • 1,072
  • 2
  • 16
  • 29