Question

Here it goes: I am refreshing a page named index.jsp via this

<head>
        <meta http-equiv="Refresh" CONTENT="0;URL=populatefields.action">

</head>

And it is calling my action. here is the mapping in my struts.xml

 <struts>

        <package name="com.action" extends="struts-default">
            <action name="*fields" method="{1}" class="com.action.RegisterAction">
    <result name="populate">/register.jsp</result>
    <result name="fields">/success.jsp</result>
<result name="error">/index.jsp</result>
    </action>

What i did here is on loading of index.jsp, i refreshed it with this url 'populatefields.action'. This calls my action class and the populate method(wildcard method invocation).Populate method picks entry from databases and assign them to form fields properties and returns "populate";Which takes the control to register.jsp with some values filled already.[i.e dynamic filling of a part of form according to the current user]

On register.jsp if some validation check is there like if(getUssername.equals("")) {this.addActionerror("Empty field -Uname-"); return error;}

The problem is on return "error" the control goes to index.jsp and then to populate method and automatic fields get populated but populate method does not throw any errors so is empty...or errors are lost ... Any idea how i can access thses errors ? by setting dem global in my action class? The actionerrors comes in index.jsp but i want to refresh that page evry time it loads to pick values form Database...can i take the value of action error from one jsp page to another ?

Was it helpful?

Solution

Done: I never thought it would be that easy.. no need to transfer the values of <s:actionerror/>.But you can do transfer your whole page using <jsp:include page='index.jsp'> if it doesnot refreshes and contains only <s:actionerror/> tag. Like when you use an <a> link to call your action, not in this case that refreshes its way to action.. But in my case i want a refresh so be it:

Just before when you type return error; copy the contents of your populate method there in your execute method. Such as

execute{
if(validation fails){populate method content(leave the return statement); 
  return error;
 }
else
return success;
}

In struts.xml change this <result name="error">/register.jsp</result>rather than <result name="error">/index.jsp</result>

Also no need to write <s:actionerror> in index.jsp,since you are now redirecting it to register.jsp so just write it in register.jsp...

Now the refresh funda working that take you to register form.. Try submitting now if validation fails same page will get called with populated fields :D and action errors...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top