*
The moose likes JSP and the fly likes Usings beans with forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Usings beans with forms" Watch "Usings beans with forms" New topic
Author

Usings beans with forms

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 102

Hello

Is it posible, in the same jsp, to set a bean property using a form and after to get that property in the same jsp



What's wrong?

I got my page redirected to a servlet, It doesn't print out the property
Log says that Bean is initialized

Thanks in advaced

This it what I have tried.

<jsp:useBean id="beanList" scope="page" class="bean.BeanLoad">
<jsp:setProperty name="beanLista" property="*" />
</jsp:useBean>

<html>
<body>

</body>


<form name="selectLista" method="post">

<select name="list"><option value="">Not selected</option>

<option value="selected">Selected</option>
</select>

<input type="submit" value="OK">

</form>

<%
if (request.getParameter("list") != null)
{
out.write("<jsp:getProperty name=\"beanList\" property=\"list\" / >");
}
%>




------------------------------
public class BeanLoad
{


private String sDesList;

/**
*
*
* @return
*/

public BeanLoad()
{
log.debug("inside");
}

public void setList(String param)
{
sDesList = param;
}

public String getList()
{
return sDesList;
}
}
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Fernando Dominguez
Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Fernando Dominguez:
Is it posible, in the same jsp, to set a bean property using a form and after to get that property in the same jsp


Yes.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Your bean's scope is set to page, which means that it will disappear after submitting. Use another scope if you want to retrieve it from a servlet.


[My Blog]
All roads lead to JavaRanch
Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 102

Originally posted by Satou kurinosuke:
Your bean's scope is set to page, which means that it will disappear after submitting. Use another scope if you want to retrieve it from a servlet.


I mean, same jsp without reloading or any else, just the same.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Then you can.
About the code you've posted, are you sure that the last "out.write" will work ? I doubt that the getParameter inside it will be interpreted.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

The answer is no. Your question is showing the same issue as your other post in which you have a misunderstanding of when and how JSP code gets executed. Did you read the article I linked to in that post?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Usings beans with forms
 
Similar Threads
LabelValueBean html:select
JSP and class paths in Websphere
Passing multiple listbox to bean using JSP
JSP select with multiple options
populating one dropdown box depending on the value of other dropdown box