Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem to get values in hasmap in bean:write

 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am setting hash map in action class
parsingForm.setMap(map);
--------------------------------------
formbean is having fallowing methods
--------------------------------------
/**
* @return
*/
public HashMap getMap() {

return map;
}

/**
* @param map
*/
public void setMap(HashMap map) {
this.map = map;
}

/**
* @return
*/

public Object getStringMapped(String key) {
System.out.println("inside parseingFormbean "+ map.get("name"));
return map.get(key);
}

/**
* @param map
*/
public void setStringMapped(String key, Object value) {
map.put(key, value);
}


------------------------------------
jsp
--------------------------------------
<jsp:useBean id="bean" class="forms.parsingForm"/>
<bean:write name="bean" property="stringMapped(name)"/>
the out put is not showing any value
the debug statment in formbean is giving null value
can any one guide me in this regard ?
thanks in advance
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

is ur instance varible in the form-bean is assigned to a new HashMap like

private HashMap map = new HashMap();

else evrything is fine and should work

and dont use <jsp:useBean> directly use bean:write to look up the value
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply
yes i created new instance of hash map in the form bean how can i avoid that one .
thanks for the reply.
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i chnaged the
HashMap map = new HashMap();
to HashMap map ;
in the form bean
how to avoid look up
<jsp:useBean id="propertyval" class="forms.parsingForm"
scope="request"/>
with bean:write as bean write does not take class as parameter
thanks for the reply
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o have used fallowing code its throwing error bean user not found

[Servlet Error]-[Cannot find bean forms.parsingForm in any scope]: javax.servlet.jsp.JspException: Cannot find bean forms.parsingForm in any scope


<logic:iterate id="user" name="forms.parsingForm" property="map">
<tr>
<td>User Id: <bean:write name=" user" property="key"/></td>
<td>Password: <bean:write name=" user" property="value"/></td>
</tr>
</logic:iterate>
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my struts config is
<action name="parsingForm" path="/parsing" type="actions.parsingAction" scope="request">
<forward name="success" path="/projselect.jsp">
</forward>
</action>


<form-bean name="parsingForm" type="forms.parsingForm">
</form-bean>


advice
thanks in advance
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changed iterate to now giving error unable to iterate
<logic:iterate id="user" name="parsingForm" type="forms.parsingForm">
<tr>
<td>User Id: <bean:write name=" user" property="key"/></td>
<td>Password: <bean:write name=" user" property="value"/></td>
</tr>
</logic:iterate>
Cannot create iterator for this collection error
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i changed as fallows its working now
<logic:iterate id="user" name="parsingForm" property="map" >
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic