steve Pentas

Greenhorn
+ Follow
since Mar 05, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by steve Pentas

So, since struts 2 always creates a new instance per request, each time whenit creates a new instance, it calls its prepare() method, and re-initialize its class variables. And these class variables will never be messed up with each other as they belong to different objects. Cool stuff !
Thanks.
9 years ago
In my struts.xml file, I have two actions, each of them maps to the *SAME* Action class but two different methods. And these two methods don't call each other. e.g. I have a "/getInventory" action link that maps to "getInventory()" method and "/getInvoice" action that maps to "getInvoice()" method of the same Action class "Order". In the "Order" class there is a "prepare" method.

Questions:

1. On my web app, when I click a link of "get inventory", it calls "/getInventory" and thus triggers the "getInventory()" method. I assume that at this time JVM instantiates an instance of "Order" class, right ? Now, there is another link of "getInvoice", when I click this link, it triggers "getInvoice()" method, does JVM instantiate a *separate* instance of "Order" class ? Or does it use the same instance that was created when I clicked "/getInventory" link ?

2. In my Order class, I have

public class Order implements Preparable, .... {

private String var1;
...

public void prepare() {
// initialize variable var1, var2, etc...
}
}

I want to know if "var1" is thread safe. I know in servlet, usually class variable is not thread-safe. How about in struts 2's action class ? For servlet it uses one instance multithread model, how about struts 2 action class ? For each action that appears in the struts xml config file, does JVM automatically generates a new action class instance each time an action link is clicked ? or does it behave the way as servlet which is to create a new thread ? If it behaves like servlet then I better not use any class variables.

I can't find accurate answers myself. ANy help will be appreciated.
9 years ago
I have a simple jsp scriplet like

<% String s = request.getParameter("var"); %>

...

<s:submit action="..." value="Submit to <%= s %> " name="submit"></s:submit>

The

value="Submit to <%= s %> " does not work. it shows "Submit to <%= s %>" on the page instead "Submit to xxx" where xxx is the parameter I get.

9 years ago
JSP
thanks. Is it possible that I don't change any configuration(i.e. use the tiles.xml only), and in "tiles.xml" I specify including another xml file which has the same DTD format as tiles.xml ?
9 years ago
In struts 2, My tiles.xml is too long and I want to break it into few files and use "include" file type syntax. I searched but couldn't find the correct syntax for that. Can someone help ?
9 years ago
When I create a branch on a file in PVCS. Does PVCS automatically lock that file so that others can not check out and check in the file in the main trunk ?
A follow-up question --- Do you mean if I use 3 box format I have to use javascript then (assume I want the "tab" over feature) ?
I want to create a html (actually JSP, but I assume this is a html issue..) which has a field that lets user enter 10 digits phone number. However, I want to separate the field into 3 box. First box contains 3 digits, user can click tab after finishing the first box, it should automatically jump to the 2nd box which contains 3 digits, and the 3rd box contains 4 digits. I am sure we have all seen such forms. I need to take the hone number input as a whole string from my "<form>". How do people usually handle such trick ?

thanks
David, thanks. Unfortunately I tried what you suggested but it did not work.

In my actual JSP, it looks like

<s:iterator value="%{customerInfo}">
<tr> table header row...
</tr>

<s:iterator value="%{address}">
<tr>
<td><s:textfield name="%{customerInfo.address.county}" value="%{county}">
</td>
...
</s:iterator>

</s:iterator>

I found that if I replace the second <s:iterator value="%{address}">
by <s:iterator value="%{customerInfo.address}"> it does not even display any value. Changing it to <s:iterator value="%{address}"> worked.

However, using ><s:textfield name="%{customerInfo.address.county}" value="%{county}"> turns out that I did not get anything from that name.

Note: I pass a <List> of "CustomerInfo". Each "CustomerInfo" contains a name and a <List> of address. Can't figure out where I did wrong.... ??

Thanks.




9 years ago

David Newton wrote:In order for S2 to think there's anything relating to "customers" there'd need to be form fields with a leading "customers" in the name, like: <s:textfield name="customers.name" or whatever. Otherwise there's zero relationship between your form fields and the collection.>



I am sorry ! I rechecked my jsp code. actually it has the 'name=' field there

I put name="%{address.county}" in front of the value="$%{address.county}"

But I really didn't get "customers" result in the save() method. it seems "show" method does pass things to the JSP. But JSP does not pass back. Could it be because when I click "save" button, it creates a new instance of "MyAction" class and the new instance does not contain anything (var) that has been set ? I am confused.
9 years ago

David Newton wrote:Well, you have no form elements that deal with customers, so no customers-related data would go to the server.



First, the <td> fields looked like

<td> <s:textfield...>

Sorry I gave the wrong information by putting <s:label> instead of <s:textfield>.

David, I didn't exactly understand what you wrote. Could you give more details ? Thanks
9 years ago
Oh, By the way, I used struts 2 so I didn't define forms for this.
9 years ago

David Newton wrote:You left out the part of the JSP that might help answer that question, namely, any of the form input fields.



Hi, Let me put more details here --

-----------
public class CustomerInfo {
private String name;
private Address address;
// bunch of getter and setter for 'name" and "address"
}

public class Address {
private String county;
private String state;
..
// bunch of getter/setter
}
--------
display.jsp:

<s:form action="save" method="post"..>
..
<s:iterator value="%{customers}" >
..
<tr>
<td><s:label name="%{name}" value="$%{name}"/></td>
<td><s:label name="%{address.state}" value="$="%{address.state}" /></td>
<td><s:label name="%{address.state}" value="$="%{address.county}" /></td>
..
</tr>

</s:iterator>
<s:submit....
></s:submit>
</s:form>

----

Basically that is all I have. It seems I missed something important and caused problem ? please tell me !!
9 years ago
I created a simple struts 2 application that first displays customer information retrieved from database and displayed on a JSP with all fields editable. Then user can edit the fields and click "save" to save it to database. I The code snippett are below and I will explain my problem at the end.

struts.xml
-------
<action name="show" class="MyAction" method='showResult">
<result type="tiles" name="success">display</result>
..
</action>

<action name="save" class="MyAction" method='saveResult">
<result type="chain" name="success">display</result>
..
</action>
---------

public class MyAction implements ParameterAware,
Preparable {
private List<CustomerInfo> customers;
public getCustomers() {...}
public setCustomer(..) {...}
public String show() {
// get data from database and save it to "cusotmers"
return SUCCESS;
}
public String save() {
int size = customers.size();
// save new "customers" (modified by user) to database
return SUCCESS;
}
}

class CustomerInfo {

private String name;
....
public String getName() {..}
public setName(..) {..}
}
---------------------------------
tiles.xml:

<definition name="display" template="..">
<put name="body" value="/../display.jsp"/>
..
</definition>
-----------------------------
display.jsp:

<s:form action="save" method="post"..>
..
<s:iterator value="%{customers}" >
..
<tr>
<td> <s:label name=".." value="$%{name}"..>
</td>
</tr>
</s:iterator>
<s:submit....
</s:submit>
</s:form>
*****************************

My problem is --- I can see results when I hit http://../myapp/show. The results are good. I cna also edit the fields on the page. However, when I clikc "save" button, using debugger I found that the "customer" is NULL in the "save" method. That means "customers" result is not passed from JSP back to the Action. Note: I am using the same action class for "show" and "save", they just call two different methods.

Why isn't the "customers" var passed from JSP ?

Thanks.
9 years ago