How to pass bean from action class to other jsp page? - struts2

It is very simple to do in servlet using request.setAttribute(). But how to do this in Struts2?
How to use that bean in other jsp page?
Please give example code.

As #AndreaLigios mentions in the comments, you'll want to generate getters and setters in your action classes.
In your JSP files, you'll be able to get them by using the <s:property> tag.

Related

How action mapping is done with struts with the help of struts-config.xml?

I would like to know how the action mapping is done by struts reading struts-config.xml file.
Will this differ between Struts1 and Struts2 - the way in which the action mapping is done?
Help me know about it.
In Struts1 action mapping is defined by the struts-config.xml action tag.
In Struts2 action mapping is defined by the struts.xml action tag.
Note, that action mapping implementation in Struts2 vary on which plugin provides it. The plugins also provide their own action configs.

using <set> tag in grails

I am new to grails. I came across a set tag which we can use in gsp pages itself to set the values which is similar to setting model from the controller.
<g:set var="home" value="something" />
so that when we write ${home} it outputs "something".
Is there any way to set the value in sessions in gsp pages itself and not from controller using set tag?
Yes you can do it in gsp pages as well. You just have to include an extra attribute scope to indicate which scopes(session, flash, page and request) you are setting the value to.
<g:set var="home" value="something" scope="session" />
If you do not include the scope option then it defaults to page.
To display the the value you just have to write ${session.home} or ${request.home} or simply ${home} for request scope. Hope this helps.
For more : https://grails.github.io/grails-doc/3.0.x/ref/Tags/set.html
Well! above answer suffices the need. Just wanted to add one more thing that gsp pages comprises of jsp internally and hence all the 9 implict objects are available on gsp pages as well.
request HttpServletRequest object
response HttpServletResponse object
out PrintWriter object used to send output to the client.
session HttpSession object
application ServletContext object associated with application context.
config ServletConfig object associated with the page.
pageContext server-specific features JspWriters.
page synonym for this
Exception handling exceptions and error page redirects.An instance of javax.servlet.jsp.JspException
You could at any point of time access these in your gsp pages.
More you can read from this.
Hope it helps!

Pass request parameters to jsf method in xhtml file?

i use el-impl-2.2.jar with jsf 2 that allows to call a method from managed bean in xhtml file and pass it params.
if i test this :
#{myBean.findById(1)}
all works fine. but now i want to retrieve params from request
i have tried this
#{myBean.findById(${param.id})}
it's not working.
any solution?
This expression #{myBean.findById(param.id)} should work. You shouldn't search in your view. You should do it in controller. Create ManagedBean and do it there.
Read mkyong article http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/.

How do I set Managed Bean field to the value of a ui:param?

I have a JSF page that is included in other JSF pages (basically a page header, with common information). This common page has its own controller and is reliant that the page which includes this common page pass it some common data.
Specifically, I am currently trying to include this common page on other pages using:
<ui:include src="commonPage.xhtml">
<ui:param name="commonData" value="#{thisPagesController.commonData}"/>
</ui:include>
Which should pass "commonData" to the commonPage.xhtml page and ideally set the "commonData" property on the CommonPageController class:
#ManagedProperty("#{commonData}")
CommonData commonData;
However, this is not working... the managed property is not getting set.
What is the proper way to do this?
See comment from BalusC. There is no standard for this in the JSF API spec. Use a composite or custom component instead.

working with multiple forms in same action class in Struts2

How do we populate\retrieve information from\into multiple forms in same action class in Struts2 ? With ModelDriven approach, action is tied to one form. With ScopedModelDriven interceptor jsp becomes dirty as one has to write model.property to access form properties. Is there a better way of doing it?

Resources