0

Set Attribute in HttpServletRequest not working!!

asked 2013-01-07 09:37:09 +0800

biswajitdas gravatar image biswajitdas
36

I want to set some values in HttpServletRequest and pass it to another zul page. But it doesn't work. Though it works when i set attribute in session and get the value in zul file. I don't want to pass the value in query string as parameter.

Below are my zul file:

page1.zul

<zk>
	<window apply="RequestParams">
		<textbox id="textBox1"></textbox>
		<button label="Submit" id="submit1"></button>
	</window>
</zk>

page2.zul

<zk>
	<zscript><![CDATA[
	import javax.servlet.http.HttpServletRequest; 
	HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
	String testValue = (String) request.getAttribute("test");
	]]></zscript>
	
	<window>
		<label value="${testValue }"></label>
	</window>
</zk>

RequestParams.java

public class RequestParams extends SelectorComposer {

	@Wire
	Textbox textBox1;
	
	@Listen("onClick = button#submit1")
	public void submitClick() throws IOException {
		System.out.println("In Submit " + textBox1.getText());
		//Executions.getCurrent().getSession().setAttribute("test", textBox1.getText());
		HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
		request.setAttribute("test", textBox1.getText());
		Executions.sendRedirect("page2.zul");
	}
}

Can any body please suggest what i'm doing wrong here? Or what is the correct approach to set some attributes in HttpServletRequest?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-01-07 19:19:46 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

Well, you are using a redirect which will cause the browser to make another request. Since its a different request than the first one, you cannot share any data with request attributes. The only choices are using the URL or the session.

link publish delete flag offensive edit
0

answered 2013-01-08 05:23:13 +0800

biswajitdas gravatar image biswajitdas
36

I got it.

Thanks gekkio!

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2013-01-07 09:37:09 +0800

Seen: 74 times

Last updated: Jan 08 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More