Avatar billede fredand Forsker
20. april 2010 - 22:44 Der er 4 kommentarer og
1 løsning

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
Avatar billede arne_v Ekspert
21. april 2010 - 02:04 #1
I would just put the JavaScript alert in the setvalue.jsp

<script type="text/javascript">
alert("%&!%&%!&%&!&");
</script>
Avatar billede arne_v Ekspert
21. april 2010 - 02:08 #2
Maybe:

<c:if test='${somevar}' >
<script type="text/javascript">
alert("¤%&%((/!");
</script>
</c:if>
Avatar billede arne_v Ekspert
21. april 2010 - 02:10 #3
If you use JSTL.

If you are stuck with the old Struts tags then:

<logic:present name="somebean"  property="someproperty">
...
</logic:present>
Avatar billede fredand Forsker
21. april 2010 - 10:32 #4
Hello Arne!

hanks for your input, I did as you told and it works fine!

Please give a svar so I can reward you!

Best reagrads
Fredrik
Avatar billede arne_v Ekspert
21. april 2010 - 15:17 #5
answer
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester