This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Dynamic forms with javascript

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody:

I am trying to migrate a struts 1 funcionality to struts 2, and i need to enable /disable, show/hide items in a form, using javascript.

My question is, if i could do a submit in javascript like this:



Only to refresh the form, and make visible another form options:



Could i use an action defined like this, to call a method that only returns
a success? :







And could I add a javascript like this?:





I used to make this, using the returned values in the request or in the session, and forwarding to the form again, in struts 1, but i have no idea how to make this in struts 2.

Thanks in advance.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure what you're asking: ultimately the rendered HTML looks very similar regardless of which version of Struts you're using (and you don't appear to be using JavaScript to hide/show anything, at least not in the sample you posted), and the JavaScript that acts on the form would be nearly identical.

Are you having a specific issue?
 
Juan Acv
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i don't know how to explain myself, my english is poor, and i know what i want to do, but only in struts 1, and i want to translate it to struts 2.


Well, I will try again:

I have a select, with an "onchange" trigger, because, depending on the value of this select, I will like to show/hide another select:

For example, i have countries, and, for example, if someone select "spain", i want to show another select:



In struts 1, i did it using javascript, making a submit and sending a hidden input value to the action, with this value (will say, a "REFRESH" string) recovered in the request, in the action, the action only makes a forward to the form again, and then, recovering the value from the request, in the jsp, i can make the "if" comparsion (I can put the code, if it is not clear), but i don't know how to make this in struts 2, i am newbie on it, and i realize that the binding beetween actions and jsp's have changed.

I dont know if in struts 2 it is possible to make a "fake submit" only to recover the values that someone have selected, and then, make possible to show/hide another parts on the form.

I can't explain myself better. Maybe it is a stupid question, and it's very easy with the new framework tools, but i am in a hurry, and i try to read about struts 2 as quick as i can, and for my project, i believe i only need to know basic struts 2 and how to develop dynamic forms. if someone can answer me this question, i will be grateful.

Greetings.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a fake submit--it's a real submit. And you're not showing or hiding things using JavaScript--you're using JSTL.

In any case, Struts 2 normally exposes values by exposing an action property as opposed to explicitly setting attributes in the request or session. A publicly-visible getter in the action is all that's needed to send a value to a JSP. You should run through the Struts 2 tutorial on the Struts 2 documentation wiki--it takes only a very short time and will show you all you need to accomplish what you're trying to do.
 
Juan Acv
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i know that struts 2 now encapsulates the data in beans, what i really don't undertand, it is how to call a specific method in an action or how to say to an action execute() method "now just refresh" or "now save my data", just the way a did it in struts 1.

Ok, sorry, i will take a look to the tutorial and examples.

Greetings.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call the action mapping that does what you want--I don't understand what the confusion is.
 
Juan Acv
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, i return to my first question:

I can have a refresh() method, map it:



and submit the action in javascript:



no?

Maybe i need a lot of examples about how to bind actions with jsp.

Like i said, i will take a look to the tutorial

Greetings.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The action mapping you're using in the JavaScript will work if: that's the complete path, but it should be absolute, not relative; and you're either using Struts 2.1 or you have configured Struts 2 to use extension-less mappings.
 
Juan Acv
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using appfuse framework, it works with struts version 2.1.8, and, yes, i believe they use extension-less mapping, reading their tutorial:

http://appfuse.org/display/APF/Using+Struts+2


Thank you very much, you have saved my life (seriously)

Greetings.



 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Wouldn't it just have been quicker to try it?)
 
Juan Acv
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After loosing my job, i have been very stressed, into a mess, trying to do this project, that it's very important to me. I have had to learn everything i thought i have learned yet about spring + hibernate, reading lot of documentation, etc...

I have been trying to translate a struts 1 application into struts 2 as quick as i could, instead of being patient and learn struts 2 starting with the basics.

I'm sorry to cause you so much trouble.

Thanks a lot.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not much trouble--it's more a streamlining thing for *you*, not me.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic