tags:

views:

181

answers:

3

I would like the following code to work, but have no idea as to how to get at the form bean outside of a struts tag.

<logic:equal name="model" property="answerType" value="TEXT">
 <%
  String keyval = "questionAnswer" + "(" + model.getAnswerType() + ")";
 %>
 <html:text property="<%= keyval %>" value=""></html:text>    
</logic:equal>

Is there any way to get at a struts form bean in a JSP so that I can use something more than struts tags to perform some processing?

Sorry if this is terribly basic but perhaps the way to put it is : is there a way for a JSP page to interact with a struts form bean without using struts tags that are form bean aware?

+1  A: 

based on form bean scope definition (session, request or ...) in you xml file you can get the from object from that scope :

example session:

MyFormBean m = (MyFormBean) session.getAttribute("<form bean name>");

you can even use JSP or JSTL tags to get this object from the scope.

mohammad shamsi
@mohammad : thanks. this is actually exactly what I was looking for. Tried it and it works perfectly! Mine was in request scope btw. I am not able to vote up myself, otherwise I would.
venky
A: 

Something about asking a question must trigger off a higher level of brain activity.

I found the answer almost immediately and credit is to : accessing-struts-formbean-attributes-from-jsp

Here is my updated code that works:

            <logic:equal name="model" property="answerType" value="TEXT">
                <bean:define id="qlabel" name="model" property="questionLabel" />
                <%
                    String keyval = "questionAnswer" + "(" + qlabel + ")";
                %>
                <html:text property="<%= keyval %>" value=""></html:text>               
            </logic:equal>
venky
A: 

There are four ways to get values from the following. 1.session 2.page 3.request 4.response 5.application

1.session You must declare scope =session

String name = request.getParameter( "username" );

where the username is get from previous page of text box or anything you specified that.

session.setAttribute("key",value); String s = session.getAttribute("key");

The value can be get until the session expires.

AdalArasan
This really has nothing to do with my question which is about struts. secondly, using the session is the easy way out and is bad practice unless there is a strong requirement that the piece of data be kept around for the life of the session.
venky