How to show a alert and then forward to an Action class with Struts?
Hello!I hope some one got an idea how to solve this problem.
(Btw I use Struts 1.3.10 in a war.)
I got this task, an action-class (StartAction) is checking for a value.
If value exist then redirect to success, else show an alert, like:
if(valueFomDataBase==null)
{
return mapping.findForward("alertmessage");
}
else
{
return mapping.findForward("success");
}
I did a quick sketch of struts-config.xml to test this, looking like:
<action-mappings>
<action path="/helloWorld" type="strutsexample.action.StartAction" name="helloWorldForm">
<forward name="success" path="/index.jsp"/>
<forward name="alertmessage" path="/alertmessage.jsp"/>
</action>
<action path="/setValue" type="strutsexample.action.SetValueAction" name="helloWorldForm">
<forward name="success" path="/setvalue.jsp"/>
</action>
<action path="/done" type="strutsexample.action.DoneAction" name="helloWorldForm">
<forward name="success" path="/done.jsp"/>
</action>
</action-mappings>
The tricky part is how to create the alertmessage.jsp, it should just be a blank page but first showing a javascript-alert saying something like "A value is missing, please click ok and fill in"
When user clicks the ok-button at the alert-message the page should forward or redirect to "/setValue"
If someone got a nice idea how to solve this, perhaps with just pure javascript or in some nice struts-pattern please let me know.
I have been googling but I just find javascripts the shows alert when user submits a form.
Best regards
Fredrik