• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to have a button set a bean value

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm sorry, I'm brand new to struts and it's blowing my mind.

What I'm trying to accomplish is a page (index.jsp) that the user does not leave. There are many buttons on it which bear the text Name1, Name2, Name3, etc. There is also a div that displays the button the user has clicked. At first it should be blank, and then as the user clicks buttons the name of the button pressed is displayed.

I would like to use a bean to store the name of the button pressed by the user.

I know how to set a bean value...



and how to use a bean value...



But how can I set the bean value only when I click the following button?



Using the following struts.xml, to make it seem to the user that they are never leaving the one page:



 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what's more is how to do write the struts tags with java?



is giving the following s-tags unrendered:



Rather than rendering the s-tag as HTML
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lynn Owens wrote:But how can I set the bean value only when I click the following button?



You can't. I think you need to back off of Struts for the moment and learn how JSP and servlets work. Without that, you are flying blind.

A Struts JSP, like any other, is simply a server-side template. Once the response is sent to the browser, where buttons can be clicked on, it's just an HTML page. Read this article to understand what JSP is all about.
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK -

Can I have a link send a variable back to the action handler?

Something like



And if so, how do I get the value of this variable in the action handler?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. The handler is long gone by the time the page reaches the browser. Read the article.

Every request is a new instance of an action. You can't think of the action as hanging around. It generates the HTML page to send to the browser and then goes away.
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't mean to upset you, I'm sorry if I am. I asked just now about a link. Nevermind. I'll go google somewhere else how to pass variables into an action handler. It's not worth arguing.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lynn Owens wrote:I don't mean to upset you, I'm sorry if I am.


You made me cry.

Seriously, how did you get "upset"?

Did you read the article?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lynn Owens wrote: how to pass variables into an action handler.



Again, you cannot pass any value into the handler that created the page. It's dead and buried. You can generate a new request and pass a variable as a request parameter. But it's a brand-spanking new request and has nothing at all to do with the request instance that generated the page.

That's a crucial concept to understand.
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I'm not sure how closely you're reading what I write. I suggested you were upset by your bold comment.

Bear, I do not intend to read a six page document to find out how to send a variable back to an action handler. I don't want to read about two county clerks or enjoy the patronage of a metaphor. I just want one thing answered, "How can I send a variable back to an action handler, and does the action handler get that variable".

What is the struts version of ?foo=bar and HttpServletRequest.getParameter(String) ?
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote: You can generate a new request and pass a variable as a request parameter. But it's a brand-spanking new request and has nothing at all to do with the request instance that generated the page.



Ding ding ding ding! You understand me now!

Bear Bibeault wrote: That's a crucial concept to understand.



Understanding is crucial, yes!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lynn Owens wrote:I suggested you were upset by your bold comment.


Bold means emphasis.

Bear, I do not intend to read a six page document to find out how to send a variable back to an action handler.


Position understood.
 
Lynn Owens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my solution...

index.jsp ...



struts.xml ...



your action handler...

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, that will create a link that will call a new instance of the action in a new request. For those following along, that will not create a call back to original request that created the page, as I originally (and apparently mistakenly) assumed that the question was about.
reply
    Bookmark Topic Watch Topic
  • New Topic