Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access java's Properties class in struts2

 
rajarao yerra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a properties file and through the Java's Properties class i am accessing the values in my property file. Now i have a requirement that i have to edit the property values.

EX: abc.properties is my properties file. in that i have entries like this
message1=hello mesage1
message2=hello mesage2
message3=hello mesage3
message4=hello mesage4
now i have to give a chance to user to edit those values(hello message1,hello message2,...). and i have to save the user give entry on that field.

Please help
Regards,
Rajarao
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rajarao, welcome to javaranch.

If you just want to know how to modify a properties file, see an example like this...
 
rajarao yerra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

Thanks for your quick reply.
But this is not what i am looking.
java: Properties myNewProp = new Properties();

JSP: <s:iterator value="%{allProps.propertyNames()}" status="rowstatus">
<s:checkboxlist name="chk" list="%{top}" id="brand" value="%{top}" />
<s:textarea id="abc" cols="10" rows="5" value="%{allProps.getProperty(top)}" />
<br/>
</s:iterator>

Here is the Problem. i would like to store the User edited content. In <s:textarea> how i have to declare this(name attribute) .

OGNL expression.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajarao, I'm not very clear what you are trying to do with that iterator. You've not used var (or id) attribute which will represent the current iteration value. You are using the work top but I don't think that will represent the current iterated item. Also why are you using checkboxlist?? I'm sure you want to generate a single checkbox for one textfield (you are using textarea and again I feel you should use textfield instead still this is your choice). If I were you, what I would do is iterate over the properties, generate one checkbox for one textfield, and use the name of the key as the name of the textfield. Something like this

When this form will be submitted, you can have a List named chk which will contain the the keys of the selected properties. You can use the keys to get the corresponding values from the request. This is the solution that I can think of. You'll need access to request parameters so you'll need to use the ParameterAware interceptor. Also I would personally also use some javascript so textareas would be disabled by default and will be enabled only when the corresponding checkbox is checked. This will allow you to only submit the values whose checkbox is checked so that unnecessary information is sent in the request...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic