tags:

views:

61

answers:

1

Hi, I am new this framework. In my page i have one dropdown and one text box. If any error comes that drop is no longer available. How to fix this.

Struts.xml:

 <action name="*DropDown"
            class="com.mmm.ehspreg2.web.action.DropdownListAction" method="{1}" />

<action name="addComment" method="add"
            class="com.mmm.ehspreg2.web.action.product.CommentAction">
            <result name="input" type="tiles">addComment</result>
            <result name="error" type="tiles">addComment</result>
            <result name="success" type="tiles">reloadList</result>
        </action>

Page:

<s:form action="addComment" method="POST">
    <s:action name="getDivisionsDropDown" id="actFetchDivisions" executeResult="true"></s:action>
    <s:action name="getPropretyTypesDropDown" id="actFetchPropretyTypes" executeResult="true" ></s:action>

<table cellspacing="0" cellpadding="3" width="100%" border="0">
                <tr>
                    <td class="error"><s:actionerror /><s:actionmessage /> <s:fielderror></s:fielderror></td>
                </tr>
                <tr>
                    <td class="bdyRecords"><s:label>
                        <s:text name="common.division" />
                    </s:label></td>
                    <td class="bdyRecords" style="width: 1px">:</td>
                    <td class="bdyRecords"><s:if
                        test="#actFetchDivisions.lstEntities.size()>0">
                        <s:select cssClass="drop" list="#actFetchDivisions.lstEntities"
                            cssStyle="width:200px" tooltip="divisionName"
                            id="select_division" listKey="id" name="comment.divisionId"
                            listValue="value"></s:select>
                    </s:if></td>
                </tr>
                <tr>
                    <td class="bdyRecords"><s:label>
                        <s:text name="common.propertytype" />
                    </s:label></td>
                    <td class="bdyRecords" style="width: 1px">:</td>
                    <td class="bdyRecords"><s:select cssClass="drop"
                        list="#actFetchPropretyTypes.lstEntities" cssStyle="width:200px"
                        tooltip="propertyTypeName" id="select_propertytype" listKey="id"
                        name="comment.propertyTypeId" listValue="value"></s:select></td>
                </tr>
                <tr>
                    <td class="bdyRecords"><s:label>
                        <s:text name="common.comment" />
                    </s:label></td>
                    <td class="bdyRecords" style="width: 1px">:</td>
                    <td class="bdyRecords"><s:textfield name="comment.commentText"
                        key="common.comment" size="50" maxlength="60" cssClass="textbxadd" /></td>
                </tr>
            </table>

</s:form>

And validation enabled by CommentAction-validation.xml

+1  A: 

You've got a few options I can think of:

Put dropdown List object in the session

When you populate your dropdown in DropdownListAction, put a reference to it in the session. That way, it will be available to you on your JSP if validation fails. One final step to this solution would be cleaning it out of the session once CommentAction has executed successfully.

Action Chaining

You could use the Chain Result type for your input result. This would allow you to automatically invoke your DropdownListAction on validation errors.

<action name="addComment" method="add" class="com.mmm.ehspreg2.web.action.product.CommentAction">
   <result name="input" type="chain">addCommentDropDown</result>
   <result name="error" type="tiles">addComment</result>
   <result name="success" type="tiles">reloadList</result>
</action>

The catch is, this may mess up the population of your input fields. You'd have to experiment with it.

Pat
Hi,The second scenario is not working.
Jothi
Did you try the first scenario? You may also be able to get it working using the Prepare interceptor: http://struts.apache.org/2.0.14/docs/prepare-interceptor.html
Pat
I tried first one.it worked.
Jothi