Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple Struts Q.......??

  • 02-05-2005 06:56PM
    #1
    Registered Users, Registered Users 2 Posts: 194 ✭✭


    I know this seems like a braindead Q but my head is melted.....

    I want to populate a form with user details taken from DB. My jsp page can find the bean but I can't seem to put the info into the relevent html text boxes.

    Any ideas??
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html> 
    	<head>
    		<meta name = "Generator" content = "Easy Struts Xslt generator for Eclipse (http://easystruts.sf.net).">
    
    		<title>ViewPoint</title>
    	</head>
    	<body>
    
    	<logic:present name="userName" scope="request">
    
    		<div align="center"><html:form action="/editprofile" onsubmit="return validateEditprofileForm(this);">			
      
    		  <table width="424" border="0">
                <tr>
                  <td width="170">Username : </td>
                  <td width="100"><html:text property="userName"><bean:write name="userName" scope="request"/></html:text></td>
                  <td width="100"></td>
                </tr>
                <tr>
    
    etc
    
    etc
    
    etc
    
    


Comments

  • Registered Users, Registered Users 2 Posts: 147 ✭✭seagizmo


    check the bean that is associated with the action. The bean has to have the a bean pattern matching the elements in the form.

    for example: getUsername()/setUsername() as the pattern therefore the property in the form would be username.

    Best not to use mixed casing in property name it gets very confusing.

    About retreving details from a DB, you can use the SetupAction to get information from a DB then an updateAction to write to the DB.

    Follow the examples at http://www.reumann.net/struts/main.do.

    regards

    SG


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    Hey,

    Im fine up to the point of populating the text fields.

    I can print the userName on the page by using
    <logic:present name="userName" scope="request"><bean:write name="userName" scope="request"/> </logic:present>
    

    I can iterate through a list using
    <logic:iterate etc...........
    

    BUT I can't seem to be able to set the text of a text field. I've tried
    <html:text property="userName" value="'<%=request.getParameter("userName")%>'">
    

    Any ideas....??


  • Registered Users, Registered Users 2 Posts: 147 ✭✭seagizmo


    pbarry wrote:
    Hey,

    Im fine up to the point of populating the text fields.

    I can print the userName on the page by using
    <logic:present name="userName" scope="request"><bean:write name="userName" scope="request"/> </logic:present>
    

    I can iterate through a list using
    <logic:iterate etc...........
    

    BUT I can't seem to be able to set the text of a text field. I've tried
    <html:text property="userName" value="'<%=request.getParameter("userName")%>'">
    

    Any ideas....??

    Hmmm, that's a good one.

    Basically, if the form attached to the action has the property set in it (for example: username).

    Then in form, I have a <html:text property="username"/> I get the property I am looking for.

    Try using less of the struts tag, some of them are deprecated anyway.

    SG


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    seagizmo,

    Apologies for not catchin on quicker, bit slow after a long wkend of boozin,

    got it working. I wasn't setting the 'user' bean to the request properly. That explains the errors..............

    cheers!


  • Registered Users, Registered Users 2 Posts: 147 ✭✭seagizmo


    pbarry wrote:
    seagizmo,

    Apologies for not catchin on quicker, bit slow after a long wkend of boozin,

    got it working. I wasn't setting the 'user' bean to the request properly. That explains the errors..............

    cheers!

    No worries bro...

    Take a look at that site I sent you, has some pretty good ideas.

    later

    SG


  • Advertisement
Advertisement