top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to set the name parameter on a multiple s:select

0 votes
503 views

Dear all,Imagine you have the following scenario:

- a property in your action: private Entity entity;
- Entity has a List entity2List
- Entity2 has a Entity3 entity3

Now, you need an s:select with multiple="true" to populate entity3. This corresponds to having a request in the form entity.entity2List[n].entity3.id (n=0,1,2...depending on how many items are selected).

Question: how should the name parameter of the s:select be like to achieve this?

I have tried the following without success (meaning entity.entity2List has is empty):

<s:select multiple="true" name="%{entity.entity2List[].entity3.id}" list="#someList" listKey="id" listValue="code"/>
<s:select multiple="true" name="entity.entity2List[].entity3.id" list="#someList" listKey="id" listValue="code"/>
posted May 29, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

I would have a setter on my action class that takes an array of ids. Then the action does the appropriate lookups, and sets the hydrated objects on the appropriate models.
You do recognize that the data you provided is ambiguous, though, right? Nothing you stated is sufficient to know *which* entity2 objects should be set on entity, just which entity3 objects you want those entity2 objects to have. In fact, if you don't happen to get a number of entity3 ids that matches the number of entity2s on entity, you've left yourself no way of knowing how to proceed. (Remember, all you get is a (potentially unordered) list of ids from the form submission, not tuples.)

answer May 29, 2013 by anonymous
Similar Questions
+1 vote

I am using s:select to create a dropdown and then checked the html. I wanted to add bgcolor as yellow. I referred to the following link

http://struts.apache.org/release/2.2.x/docs/struts-2-themes.html

but still not sure how to put the background clour as yellow. Can anyone provide any pointers? Also, is it OK to use JSTL tags in JSPs in a Struts 2 application ?

+1 vote

In struts2 , defined an interceptor, it triggered by Action, my question is

"inside the interceptor class, what is the function call that can tell caller's name, because that interceptor could be triggered by different Action, we need to log the caller's name, but how?"

+2 votes

I have a couple of old struts 2 apps that are using 2.2.1. I want to upgrade them to 2.3. What is the minimal set of jar files I need in WEB-INF/lib?

I currently have:
commons-beanutils-1.7.jar
commons-collections-2.1.jar
commons-digester-1.7.jar
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
commons-javaflow-20060411.jar
commons-lang-2.5.jar
commons-logging-1.0.4.jar
freemarker-2.3.16.jar
ibatis-2.3.2.715.jar
itext-1.3.1.jar
jasperreports-2.0.5.jar
javamail.jar
javassist-3.8.0.GA.jar
jdt-compiler-3.1.1.jar
jstl.jar
jxl-2.6.jar
log4j-1.2.14.jar
ognl-3.0.jar
poi-3.0.1-FINAL-20070705.jar
spring.jar
standard.jar
struts2-core-2.2.1.jar
struts2-jasperreports-plugin-2.0.11.1.jar
urlrewrite-3.2.0.jar
xalan.jar
xercesImpl.jar
xwork-core-2.2.1.jar

+7 votes

I have an Interceptor that wants to put something in the session after the action has executed.

But if the session doesn't already exist I get an exception:

java.lang.IllegalStateException: Cannot create a session after the response has been committed

How can I determine if the session already exists from within an Interceptor?

 public String doIntercept(ActionInvocation invocation) throws Exception
 {
 String result = invocation.invoke();
 Map session = invocation.getInvocationContext().getSession();
 session.put(key, value); // throws exception if session doesn't exist
 return result;
 }
...