Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 02-05-2005 6:56pm
    #1
    Registered Users 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 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 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 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 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 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