File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to have a button set a bean value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to have a button set a bean value" Watch "How to have a button set a bean value" New topic
Author

How to have a button set a bean value

Lynn Owens
Greenhorn

Joined: Aug 24, 2012
Posts: 19
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

Joined: Aug 24, 2012
Posts: 19
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lynn Owens
Greenhorn

Joined: Aug 24, 2012
Posts: 19
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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

Joined: Aug 24, 2012
Posts: 19
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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

Joined: Aug 24, 2012
Posts: 19
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

Joined: Aug 24, 2012
Posts: 19
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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

Joined: Aug 24, 2012
Posts: 19
Here's my solution...

index.jsp ...



struts.xml ...



your action handler...

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.
 
jQuery in Action, 2nd edition
 
subject: How to have a button set a bean value