Fetching some variables in hidden field using struts2
<s:hidden name="ABCFormBean.dependentLists[0].lastNameEng" id="h_dependantLastNameEng_id"/>
I need to display the same in the same page
<s:property value="ABCFormBean.dependentLists[0].lastNameEng"/>
doesnt work
how to display the content?
Nothing gets displayed because the property value doesn't map the value in the value stack. Bu default the action is on top of the value stack. If you map properties they should should be initialized and have getters and setters. To display
<s:property value="ABCFormBean.depLists[0].firstNameEng"/>
the following method calls are expected
getABCFormBean().getDepLists().get(0).getFirstNameEng()
If you can get this value in the action method, then you would have the values been displayed by the property tag.
Related
I have a scenario in which i am rendering a jsp page .One of my value is in my model Form entity.I am assigning it in one of my form input like below :
<s:hidden name="myModelName.myUserName"/>
I am trying to assign it to my java variable inside my jsp.I tried accessing the model directly like this
<%= String myName = myModelName.myUserName %>
But i get error message "myModelName cannot be resolved.I have then tried accessing from the hidden field.But i dont know how to use it.Anyway i need the value in java variable inside jsp for some reason.Anyone help me out how to do it
You can do something like this:
assign your model property value to variable userName
<c:set var="userName" scope="session" value="${myModelName.myUserName}"/>
and then you can output it using this tag:
<c:out value = "${userName}"/>
You can read more about JSTL tags here: Using JSTL tags
Hope this helps. Ask if you need anything else.
I'm looping over a list and want to access the value to create a text input field. Unfortunatley I'm failing to access the loop variable inside the <s:textfield> tag
This is what I tried:
<s:iterator var="tag" value="searchTagList">
<s:property value="#tag"/>
<s:textfield key="searchResults.#tag" name="#tag" value="#tag" />
</s:iterator>
The <s:property value="#tag"/> is evaluated correctly and shows the loop variable. But the #tag in the <s:textfield> is never evaluated.
I also tried to put <s:property value="#tag"/> instead of #tag without success.
The tag's key attribute used instead of three ones name,value,label. As far as two of them you have already defined, you can change
<s:textfield label="%{getText('searchResults.'+#tag)}" name="%{#tag}" />
The value is retrieved by the name attribute. You should provide a getter for the name evaluated in the name attribute. Note, getText() is available if your action extends ActionSupport. And you have to force name evaluation in the name tag.
How do I select a specific object from the action class when pulling up multiple objects in JSP.
From my action class I pass through Struts five of the same object. In JSP how would I select a specific object and property of the object to display on page. I have tried putting various values and names in the <s:form> tag but I have yet to figure out how to do it. A push in the corrected direction would be welcome.
Use
<s:iterator value="walkthroughs" >
<s:property value="id"/><br>
<s:property value="areaName"/><br>
...
</s:iterator>
And you should rename your getter methods to be bean compartible.
getId(), getAreaName()
I am new to Struts2.I unable to pass tag value dynamically through javascript.I have done this way
<s:url id="temId" action="updateProduct.action" var="productTag">
<s:param name="prodId"><s:property value="hdnId"/></s:param>
</s:url>
<s:hidden name="hdnId"/>
this hidden field value is populated through javascript function onclick on gridrow
This hidden field is storing value properly.But it is not showing inside of param tag.please give some possible solution
AFAIK Struts2 is server side only whereas JavaScript is client side. Thus you can't create/fill struts tags using JavaScript (unless you execute it on the server side which wouldn't make sense IMHO).
How to declare a variable and assign value to that variable in Struts2?
Use the set tag:
<s:set var="myVar">hello</s:set>
read the var with:
<s:property value="#myVar"/>
Another example:
<s:set name="personName" value="person.name"/>
Hello, <s:property value="#personName"/>. How are you?
where person is a bean in your value stack
You shouldn't have to declare variables in JSPs. Do it in your Action and create a getter so you can access it from the JSP showing the action's output.
Well in struts2 we have concept of value stack and during request processing Struts2 framework will push the action on the top of value stack and its properties (Variable) will work as they are on the top of it.
all you need to have getter and setter for your variable and you can than access values both (in/out) in struts2 with OGNL.OGNL is an expression language integrated with Struts2 which is capable of refereeing values from the value stack and also will do the data conversion (except custom type) for you