Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Usings beans with forms

 
Fernando Dominguez
Ranch Hand
Posts: 106
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Fernando Dominguez
Ranch Hand
Posts: 106
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic