2

I've done similar things to this before, but never using this particular configuration. Every example I look up shows the dropdown having the options set within the controller, when I don't want them set line by line in the controller, but pulled from a column in a SQL database.

I have other forms that currently pull from the same table and column, but with the drop down. I get nothing. Here is the JSP

This is what I have in the jsp, previously I used a c:forEach, and I suspect I might have to put that back in used in conjunction with with jsp use bean...

<table>
    <tr>
        <td>Job:</td>
        <td>    
            <form:select path="Job.jobName">
                <form:option value="" label="Select Job"/>
                <form:options value="" items="${job.jobName}"/>
            </form:select>
        </td>
        <td><form:errors path="job.jobName" /> </td>
    </tr>
</table>

This is the method call in the controller, there is more than this, but it's what I"m using..

List<Job> jobList = jobService.listjobsByPage(page);

and here is the query into the DAOImpl

public List<Job> getDataByJobName(String jobName) {            
     Session session = sessionFactory.openSession();
     List<Job> result = null;
     try{
            session.beginTransaction();
            Query query = session.createQuery("from Job where upper(jobName) like ? " +
                         "order by jobName");
            query.setParameter(0, "%" + jobName + "%");
            result = query.list();
            session.getTransaction().commit();
            session.close();
     } catch(Exception e){
            e.printStackTrace();
     }
     return result;
}

If anyone can even point me in the right direction on how to set this up that would be a great help.

Thanks in advance.

2 Answers 2

2

You have to do first :

    ModelAndView model = new ModelAndView("index");
    model.addObject("lists", list);

than

    <form:select path="list">
        <form:options items="${lists}" />
    </form:select>
Sign up to request clarification or add additional context in comments.

2 Comments

OK, I did all this, and now I get a nullpointerexception. This is sort of where I was at before. It all comes back to that list method in the StackTrace.
Just check is your list is empty or not i am afraid you passing any empty list .But even you pass empty list , it should not give you nullpointer. Please attache your logs and latest code with controller
0
<form:options value="" items="${job.jobName}"/> 

An other fail is the dropdown value will be always nothing because of value="".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.