venky
venky

Reputation: 153

Manipulate Struts Form Bean Data Outside of Struts Tags

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?

Upvotes: 1

Views: 5313

Answers (3)

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.

Upvotes: 0

venky
venky

Reputation: 153

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>

Upvotes: 0

mhshams
mhshams

Reputation: 16972

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.

Upvotes: 4

Related Questions