aspose file tools*
The moose likes Struts and the fly likes problem to get values in hasmap in bean:write Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem to get values in hasmap in bean:write" Watch "problem to get values in hasmap in bean:write" New topic
Author

problem to get values in hasmap in bean:write

kamesh aru
Ranch Hand

Joined: Mar 16, 2002
Posts: 150
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

Joined: Sep 21, 2003
Posts: 415
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

Joined: Mar 16, 2002
Posts: 150
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

Joined: Mar 16, 2002
Posts: 150
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

Joined: Mar 16, 2002
Posts: 150
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

Joined: Mar 16, 2002
Posts: 150
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

Joined: Mar 16, 2002
Posts: 150
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

Joined: Mar 16, 2002
Posts: 150
i changed as fallows its working now
<logic:iterate id="user" name="parsingForm" property="map" >
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem to get values in hasmap in bean:write
 
Similar Threads
Problem while using Map in ActionForm
How can I parse url query string parameter in java?
same key for diff values in HashMap
Getting custom key from map based on comparator etc.
how to store multiple values in one key in hash table