Wednesday, April 13, 2011

How to get value from struts bean?

I am new to struts. I'm just trying to build a simple application that gets the input from the user and display it. For which I got the input from the user and stored it in a bean and I have also displayed it in the next page using bean:write but how to place it in a text box. I tried to use html:text but I don't know how to place the value in it.

Thanks in advance

From stackoverflow
  • Set the property or bean that you want to display in the request attribute and fetch the value from it in the final page:

    The syntax for inserting a value in text box is

    <html:text property="propertyName" value="value"></html:text/>
    
    : I think you didn't understand my question. I want to get the value from the previous page. Anyway thanks for your reply.
    : If I am using request attribute then there is no point in using bean isn't it
  • You need to wrap html:text with html:form. The action attribute of html:form will point to an action defined in struts-config.xml. This action will be associated with a form bean where you have stored the value you are talking about. Then in html:text refer to that property like this

    <html:text property="property name where the value is stored"/>

  • Both the answers didn't help me. Can anyone plz lend a hand, it's urgent.

  • If you want to place that in a text box I think you might want to try textfield tag

  • You can use "" to directly get the value of the property from the bean. Ex:

    <bean:write name="user" property="username" />
    Replace by this:
    <html:text name="user" property="username" style="width:150" maxlength="20"/>
    
    In that:
    name - is the bean object name
    property - is the property of the bean object
    

    Good luck!

0 comments:

Post a Comment