0

I have this exception (java.lang.IllegalArgumentException), I'm trying to make search based on fields. if the user enter all or any of these fields the result will be show in the page, and when the user not enter any values only the user click on the search bottom also the result show in the page including all the records of the DB.

I have this exception, I think is related to the action of the CommendLink that is on the JSP page:

javax.faces.event.AbortProcessingException: /SearchIdeas.jsp(148,24) '#{searchIdeasBean.doSearch}' java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:118)

DaO:

public List<SearchResultDto> search(SearchDto searchDto) {
Connection connection = null;

PreparedStatement preparedStatement = null;
ResultSet searchResultSet = null;

try {
    connection = getConnection();
    preparedStatement = connection.prepareStatement(
            "SELECT I_ID, I_NO, I_TITLE, I_DESCRIPTION, I_CREATED_DATE, STATUS.S_DESCRIPTION, APPL_USER.U_NAME FROM IDEA IDEA, STATUS STATUS, APPL_USER APPL_USER WHERE IDEA.I_STATUS_CODE = STATUS.S_CODE AND IDEA.I_CREATED_USER_ID = APPL_USER.U_SEQ AND IDEA.I_NO = ? OR IDEA.I_TITLE LIKE ? OR TRUNC(IDEA.I_CREATED_DATE)= ?  OR STATUS.S_CODE = ? ");



    // Assign first value to first parameter
    preparedStatement.setLong(1, searchDto.getIdeaNo());
    preparedStatement.setString(2, "%"searchDto.getIdeaTitle()"%");
    preparedStatement.setDate(3, searchDto.getCreatedDate() == null ? null
            : new java.sql.Date(searchDto.getCreatedDate().getTime()));
    preparedStatement.setObject(4, searchDto.getIdeaStatus());

    searchResultSet = preparedStatement.executeQuery();

    return search(searchResultSet);

} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    try {
        if (searchResultSet != null) {
            searchResultSet.close();
        }

        preparedStatement.close();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
}

private List<SearchResultDto> search(ResultSet searchResultSet) throws SQLException {
List<SearchResultDto> result = new ArrayList<SearchResultDto>();

SearchResultDto searchResultDto = null;

while (searchResultSet.next()) {
    ideaSearchResultDto = new SearchResultDto();

    searchResultDto.setIdeaId(searchResultSet.getLong(1));
    searchResultDto.setIdeaNo(searchResultSet.getLong(2));
    searchResultDto.setTitle(searchResultSet.getString(3));
    searchResultDto.setDescription(searchResultSet.getString(4));
    searchResultDto.setCreatedDate(searchResultSet.getDate(5));
    searchResultDto.setStatusDescription(searchResultSet.getString(6));
    searchResultDto.setIdeaCreator(searchResultSet.getString(7));

    result.add(searchResultDto);

}

JSp:

td><rich:panel>
                                    <table>
                                        <tr>
                                            <td>
                                                <table>
                                                    <tr>
                                                        <td width="70px"><h:outputText value="No"></h:outputText>
                                                        </td>
                                                        <td width="5px"> </td>
                                                        <td><h:inputText

                                                                maxlength="10" style="width:150px"
                                                                value="#{searchBean.searchDto.no}"></h:inputText>
                                                        </td>
                                                        <td width="50px"> </td>
                                                        <td width="70px"><h:outputText value="status"></h:outputText>
                                                        </td>
                                                        <td width="5px"> </td>
                                                        <td><h:selectOneMenu
                                                                value="#{searchBean.searchDto.status}"
                                                                style="width:150px">
                                                                <f:selectItems value="#{searchBean.statuses}" />
                                                            </h:selectOneMenu></td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table>
                                                    <tr>
                                                        <td width="70px"><h:outputText value="Title"></h:outputText>
                                                        </td>
                                                        <td width="5px"> </td>
                                                        <td><h:inputText maxlength="100"
                                                                value="#{searchsBean.searchDto.Title}"
                                                                style="width:150px"></h:inputText></td>
                                                        <td width="50px"> </td>
                                                        <td width="70px"><h:outputText value="created Date"></h:outputText>
                                                        </td>
                                                        <td width="5px"> </td>
                                                        <td><rich:calendar
                                                                value="#{searchBean.searchDto.createdDate}"
                                                                datePattern="yyyy-MM-dd" inputStyle="width:150px"></rich:calendar>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>

                                    </table>
                                </rich:panel></td>
                        </tr>
                    </table>
                </td>
            </tr>


            <tr>
                <td width="100%" align="center">
                    <table>
                        <tr>

                            <td width="3px"><h:commandButton image="search.png"
                                    actionListener="#{searchBean.doSearch}"></h:commandButton>
                            <td width="3px"><h:commandButton image="clean.png"
                                    actionListener="#{searchBean.doClear}"></h:commandButton>

                        </tr>
                    </table>
                </td>
            </tr>





            <tr>
                <td>
                    <table>
                        <tr>
                            <td><rich:datascroller renderIfSinglePage="false" align="center" for="ideasTable"
                                    id="ideasTableScroller" /> 
                                    <rich:dataTable
                                    rendered="#{searchBean.showResultsTable}" rows="15"
                                    rowClasses="odd-row, even-row"
                                    value="#{searchIBean.result}" var="record"
                                    id="ideasTable">
                                    <rich:column width="80px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="No"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.no}"></h:outputText>
                                    </rich:column>
                                    <rich:column width="250px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="title"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.title}"></h:outputText>
                                    </rich:column>
                                    <rich:column width="90px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="description"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.description}"></h:outputText>
                                    </rich:column>
                                    <rich:column width="90px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="created Date"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.createdDate}"></h:outputText>
                                    </rich:column>
                                    <rich:column width="80px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="status"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.statusDescription}"></h:outputText>
                                    </rich:column>
                                    <rich:column width="70px" style="text-align: center;">
                                        <f:facet name="header">
                                            <h:outputText value="creator"></h:outputText>
                                        </f:facet>
                                        <h:outputText value="#{record.creator}"></h:outputText>
                                    </rich:column>

                                    <rich:column width="115px" style="text-align: center;">
                                        <table width="100%">
                                            <tr>
                                                <td><h:commandLink
                                                        action="#{searchBean.goDetails}" value="Details">
                                                        <f:param name="ideaId" value="#{record.id}"></f:param>
                                                    </h:commandLink></td>
                                            </tr>

                                            <tr>
                                                <td><h:commandLink
                                                        action="#{searchBean.goAttachments}"
                                                        value="Attachments">
                                                        <f:param name="ideaId" value="#{record.id}"></f:param>
                                                    </h:commandLink></td>
                                            </tr>

                                        </table>
                                    </rich:column> 
                                </rich:dataTable></td>
                        </tr>
                    </table>
                </td>
            </tr>


        </table>

I have this method in the bean:

public void doSearch(ActionEvent actionEvent) {
Delegate delegate = new Delegate();

result = delegate.search(searchDto);

if (result == null || result.size() == 0) {
    addInformationMessage("no data");
}
}


public String goDetails() {
long ideaId = Long.parseLong(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("ideaId"));

FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("ideaId", 
    ideaId);

return "goIdeaDetails";

}

faces-config.xml:

<navigation-rule>
<display-name>Search</display-name>
<from-view-id>/Search</from-view-id>
<navigation-case>
    <from-outcome>goIdeaDetails</from-outcome>
    <to-view-id>/IdeaDetails</to-view-id>
</navigation-case>
</navigation-rule>

any help! Thank you in advance,

uma
  • 93
  • 6
  • Post a stacktrace, not just the exception. And posting the root cause of a stacktrace in a search engine will, in 99% of the cases, result in finding an answer – Kukeltje Oct 19 '18 at 06:59
  • Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentExceotion at Dao.search(Dao.java:355) at Delegate.search(Delegate.java:146) … 48 more Caused by: java.lang.IllegalArgumentExceotion at java.sql.Date.valueOf(Unknown Source) – uma Oct 19 '18 at 15:11
  • I’m waiting for your comments – uma Oct 20 '18 at 06:47
  • I'm waiting for a full stacktrace, but most likely you have a JPA problem.... – Kukeltje Oct 20 '18 at 07:29

0 Answers0